How to pass objects list from jsp to Struts?
How to post objects list from jsp to Struts?
Struts 2 framework have provided very powerful features using OGNL to post list of Objects from jsp to Struts 2 Action class.
Here is the example of passing list of objects from jsp to Struts.
We must have Struts 2 framework with OGNL script.
Following example will allows you to add multiple user list at the same time from jsp.
Code of required POJO, Acion Class and Jsp to post list of Person Object from jsp to action class are written below.
Person.Java Pojo
How to post objects list from jsp to Struts?
Struts 2 framework have provided very powerful features using OGNL to post list of Objects from jsp to Struts 2 Action class.
Here is the example of passing list of objects from jsp to Struts.
We must have Struts 2 framework with OGNL script.
Following example will allows you to add multiple user list at the same time from jsp.
Code of required POJO, Acion Class and Jsp to post list of Person Object from jsp to action class are written below.
Person.Java Pojo
public class Person { int person_id; String name; String address; public int getPerson_id() { return person_id; } public void setPerson_id(int personId) { person_id = personId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } }Struts 2 Action Class
@ParentPackage("default") public class ManageUsers extends ActionSupport { List<Person> personList ; @Action(value="addUserList",results={ @Result(name=ActionSupport.SUCCESS,location="addPersonList",type="tiles")}) public String execute() throws Exception { if(personList==null) { personList = new ArrayList<Person>(); } Person p = new Person(); p.setName("NAME"); personList.add(p); return SUCCESS; } public List<Person> getPersonList() { return personList; } public void setPersonList(List<Person> personList) { this.personList = personList; } }JSP
<s:if test="personList != null && personList.size > 0"> <tr> <th width="50%">Person Name</th> <th width="50%">Address</th> </tr> <s:iterator value="personList" status="p"> <tr> <td><s:textfield name="personList[%{#p.index}].name" /></td> <td><s:textfield name="personList[%{#p.index}].address" /></td> </tr> </s:iterator> </s:if>