「struts2」JSP画面でラジオボタン動的を生成するサンプル

説明
△ .s:iteratorタグ
staus:指定された場合、IteratorStatusのインスタンスは、スタックの上に積まれる。
value:繰り返可能しソース
1.Actionクラス側

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Map<String, String> empA = new HashMap<String, String>();
Map<String, String> empB = new HashMap<String, String>();
List<Map<String, String>>empList = new ArrayList<Map<String, String>>();
//指定された値と指定されたキーをこのマップAで関連付けます
empA.put("ID", "10001");
empA.put("nam", "次郎");
empA.put("age", "21");
empA.put("dep", "SE");
//empListリストの最後に指定された要素empAを追加します。
empList.add(empA);
//指定された値と指定されたキーをこのマップBで関連付けます
empB.put("ID", "10002");
empB.put("nam", "太郎");
empB.put("age", "35");
empB.put("dep", "PG");
//empListリストの最後に指定された要素empBを追加します。
empList.add(empB);
Map<String, String> empA = new HashMap<String, String>(); Map<String, String> empB = new HashMap<String, String>(); List<Map<String, String>>empList = new ArrayList<Map<String, String>>(); //指定された値と指定されたキーをこのマップAで関連付けます empA.put("ID", "10001"); empA.put("nam", "次郎"); empA.put("age", "21"); empA.put("dep", "SE"); //empListリストの最後に指定された要素empAを追加します。 empList.add(empA); //指定された値と指定されたキーをこのマップBで関連付けます empB.put("ID", "10002"); empB.put("nam", "太郎"); empB.put("age", "35"); empB.put("dep", "PG"); //empListリストの最後に指定された要素empBを追加します。 empList.add(empB);
Map<String, String> empA = new HashMap<String, String>();
Map<String, String> empB = new HashMap<String, String>();
List<Map<String, String>>empList = new ArrayList<Map<String, String>>();
//指定された値と指定されたキーをこのマップAで関連付けます
empA.put("ID", "10001");
empA.put("nam", "次郎");
empA.put("age", "21");
empA.put("dep", "SE");
//empListリストの最後に指定された要素empAを追加します。
empList.add(empA);
//指定された値と指定されたキーをこのマップBで関連付けます
empB.put("ID", "10002");
empB.put("nam", "太郎");
empB.put("age", "35");
empB.put("dep", "PG");
//empListリストの最後に指定された要素empBを追加します。
empList.add(empB);

2.JSP画面

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<s:iterator value="empList" status="stat">
<s:textfield name="empList" type="radio" value="%{empList[#stat.index]['ID']}"></s:textfield>
<s:property value="%{empList[#stat.index]['nam']}"></s:property>
<s:property value="%{empList[#stat.index]['age']}"></s:property>
<s:property value="%{empList[#stat.index]['dep']}"></s:property>
</s:iterator>
<s:iterator value="empList" status="stat"> <s:textfield name="empList" type="radio" value="%{empList[#stat.index]['ID']}"></s:textfield> <s:property value="%{empList[#stat.index]['nam']}"></s:property> <s:property value="%{empList[#stat.index]['age']}"></s:property> <s:property value="%{empList[#stat.index]['dep']}"></s:property> </s:iterator>
<s:iterator value="empList" status="stat">
    <s:textfield name="empList" type="radio" value="%{empList[#stat.index]['ID']}"></s:textfield>
    <s:property value="%{empList[#stat.index]['nam']}"></s:property>
      <s:property value="%{empList[#stat.index]['age']}"></s:property>
      <s:property value="%{empList[#stat.index]['dep']}"></s:property>
</s:iterator>

 

Struts2

Posted by arkgame