access data of struts2 nested iterator in action
<s:iterator var="parent" value="studentList">
   <s:iterator var="child1" value="#parent.subjectList">
       <s:property value="%{subjectName}" />: 
       <s:textfield id="subject" name="%parent.subject.id}" theme="simple" />
   </s:iterator>   
</s:iterator>
I have a jsp page with the above code. I have two lists i) studentList, ii) subjectList. For each student there is a subjectList. Now I have to save the mar开发者_如何学JAVAks. How can I get these values in my action ? I am using Struts2. Thanx in advance.
This is how the JSP code will look like:
    <s:form action="saveaction" >
        <s:iterator value="lstBean" id="lstBean" status="outerStat">
            <s:textfield value="%{name}" name="lstBean[%{#outerStat.index}].name"/>
            <s:textfield value="%{amt}" name="lstBean[%{#outerStat.index}].amt"/>
            <s:textfield value="%{id}" name="lstBean[%{#outerStat.index}].id"/>
            <s:iterator value="%{lstString}" status="myStat">
                <s:textfield name="lstBean[%{#outerStat.index}].lstString[%{#myStat.index}]"/>
            </s:iterator>
        </s:iterator>
        <s:submit value="Click me to submit lstBean"/>
    </s:form>
Following is the bean(XBean) whose List is used in the JSP:
public class XBean
{    
private ArrayList<String> lstString=new ArrayList<String>();
private String name;
private Double amt;
private Integer id;
//Getters and setters of fields
}
Now you can simply have a field lstBean with setters in your submitting action (saveaction) and hey you are done.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论