2012-04-21 34 views
-1

テキストボックスとドロップダウンリストを使用して動的にhtmlテーブルを生成すると、ユーザはその入力を入力します。アクションコードは、どのようにそのデータを取得し、ここでは、あなたのテーブル内のすべての行のパラメータ行識別子を追加する必要がありますStruts2の動的に作成されたテーブルからデータを取得する方法

答えて

0
<form action="/my_action_path/my_action.do"> 
    <table> 
     <tr> 
     <td> 
      //This is your row id 
      <input type="hidden" name="rowId" value="**1**"/> 

      <input type="text" name="first_textbox_**1**"/> 
     </td> 
     <td> 
      <input type="text" name="second_textbox_**1**"/> 
     </td> 
     </tr> 
     <tr> 
     <td> 
      //This is your row id 
      <input type="hidden" name="rowId" value="**2**"/> 

      <input type="text" name="first_textbox_**2**"/> 
     </td> 
     <td> 
      <input type="text" name="second_textbox_**2**"/> 
     </td> 
     </tr> 
    </table> 
    <input type="submit"/> 
    </form> 

2を使用してActionクラスに渡すことです

import java.lang.String; 

public class MyAction extends ActionSupport { 
    //Struts put all your "rowId" values here 
    private String[] rowId = new String[]; 

    public String execute(){ 
    //Get "request" object 
    HttpServletRequest request = ServletActionContext.getRequest(); 
    //Read all your parameters using they names 
    for(int i = 0; i< rowId.length; i++){ 
     String firstTextbox = (String) request.getParameter("first_textbox" + "_" + i); 
     String secondTextbox = (String) request.getParameter("second_textbox" + "_" + i); 
     //Ta-dam. Your have your parameters from the row i 
    } 
    } 

    public String[] getRowId() { 
    return rowId; 
    } 

    public void setRowId(String[] rowId) { 
    this.rowId = rowId; 
    } 
} 
+0

どうもありがとうワシリー –

関連する問題