Note that there are some explanatory texts on larger screens.

plurals
  1. POa list of list value populated in struts2 iterator
    text
    copied!<p>For my case, it is a little bit trickier. I just have another list in person object, it is called state. like below:</p> <pre><code>public class People { private int id; private String name; private List&lt;State&gt; states; // Plus setters/getters } public class State { private int id; private String stateAbbr; private String stateName; public State (String stateAbbr, String stateName) { this.stateAbbr = stateAbbr; this.stateName = stateName; } // Plus setters/getters } </code></pre> <p>Action class:</p> <pre><code>public class PersonAction extends ActionSupport { private List&lt;People&gt; peopleList; public List&lt;People&gt; getPeopleList() { return peopleList; } public void setPeopleList(List&lt;People&gt; peopleList) { this.peopleList = peopleList; } //Initial Load method @Override public String execute() { peopleList = new ArrayList&lt;People&gt;(); int alpha = 65; for(int i = 0; i &lt; 3 ; i++) { People people = new People(); people.setId(i); people.setName(String.valueOf((char)alpha++)); peopleList.add(people); } for (People people : peopleList){ State state = new State("BC", "BritishColumbia"); List&lt;State&gt; states = new ArrayList&lt;State&gt;(); states.add(state); state = new State("AC", "AppleColumbia"); states.add(state); people.setStates(states); } return SUCCESS; } //Function that handles the form submit public String updatePerson() { for(People people : peopleList) { System.out.println(people.getId() + ":" + people.getName()); } return SUCCESS; } </code></pre> <p>}</p> <p>JSP page</p> <pre><code>&lt;s:form action="doUpdate"&gt; &lt;s:iterator value="peopleList" status="stat" var="people"&gt; &lt;s:textfield value="%{#people.name}" name="peopleList[%{#stat.index}].name" /&gt; &lt;s:iterator value="states" status="stateStatus" var="personState"&gt; &lt;s:textfield value="%{#personState.stateAbbr}" name="peopleList[%{#stat.index}].states[%{#stateStatus.index}].stateAbbr" label="Abbr State" /&gt; &lt;br /&gt; &lt;/s:iterator&gt; &lt;/s:iterator&gt; &lt;s:submit value="Submit" /&gt; &lt;/s:form&gt; </code></pre> <p>When I submit this page, I got states is [null] in person, why?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload