RKG RKG - 4 months ago 62
Java Question

How can we pass list object from jsp to struts2 action?

I'm facing one issue in Struts2, Please find below information.

Java Code:

public class Employ{
int empNo;
String empName;

class EmployAction{
List<Employ> empList=new ArrayList<Employ>();
int eno;
String ename;

<s:iterator value="empList">
<s:textfield name="eno" value="%{empNo}"/>
<s:textfield name="eName" value="%{empName}"/>

First I'm doing search operation and getting all employs list and iterating in JSP.

Whenever I'm submitting form this
object is not passing to Action class. I want this List Object for some other processing.

How can i pass this list object to Action class? Note: Here I'm not using any of List Object fields as Named parameters in fields.


After long investigation found solution and fixed this issue. This solution might be helpful to any one else.

<s:iterator value="empList" status="emp">
<s:textfield name="eno" value="%{empNo}"/>
<s:textfield name="eName" value="%{empName}"/>
<s:hidden name="empList[%{#emp.index}].eno" value=%{empNo}/>
<s:hidden name="empList[%{#emp.index}].ename" value=%{empName}/>

Best Regards, Ravi Kumar