jQuery in Action, 3rd edition
The moose likes Struts and the fly likes Populating a list of Objects in Struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Populating a list of Objects in Struts2" Watch "Populating a list of Objects in Struts2" New topic

Populating a list of Objects in Struts2

Gopal Venkatakrishnan

Joined: Mar 12, 2008
Posts: 1

I am trying to populate a list of objects using struts 2.0 s:iterate tag with java.util.List in the Action. I am able to load populate the data from Action to the form but after submitting the form the List in the action is not getting updated with the new data.

My Action class is like this:

public class TestAction extends ActionSupport {

private List<Employee> empList;

public String execute() throws Exception {

// after submitting i put break point here and checked the value of
// empList and the value is null
empList = new ArrayList<Employee>();
Employee emp1 = new Employee();
Employee emp2 = new Employee();
return SUCCESS;
public List getEmpList() {
return empList;
public void setEmpList(List<Employee> empList) {
this.empList = empList;

My form looks like this:

<s:form action="test">
<s:iterator value="empList">
<s:textfield name="name"></s:textfield>

What I need to change in the jsp or action so that the List in the Action reflects the data submitted.
kal til

Joined: Apr 03, 2008
Posts: 2
Use the Struts automatic type conversion to facilitate your conversion.
Populate the fields in jsp page as

<s:form action="test">
<s:iterator value="empList" status="stat">
<s:textfield name="empList[%{#stat.index}].name" value="%{name}" label="name" />
<s:submit />

Create conversion.properties file with name as ActionName-conversion.proeprties and add the following properties


In action class don't forget to create a Employee bean with setter().

I agree. Here's the link: http://aspose.com/file-tools
subject: Populating a list of Objects in Struts2
It's not a secret anymore!