Reputation: 531
I am working on Struts2 web application and currently i am facing issue with the form binding. The binding from jsp to the action class is not working.
The scenario is i am having a list which is being set from the previous action. In current jsp I am iterating over the list and printing the values in the Table in jsp. Due to a requirement i am supposed to make the fields editable so that user can edit the values displayed and submit the updated values to the next action.
The problem is that the values that i edit from the jsp are not being bound to the list in action class. I have tried multiple ways but no luck till now. below are the ways that i have tried.
The First way i tried values are not getting bound:
<s:iterator value="list1" var="sVO" status="rowStatus">
<tr onclick="SelIndex('<s:property value="itm_id"/>');">
<td><s:property value="itm_id"/></td>
<td><s:date name="proc_d" format="MM/dd/YYYY"/></td>
<td><span style="display:none;"><s:property value="pln_n_n"/></span><input type="text" size = "8" value="<s:property value="pln_n_n"/>"/></td>
<td><span style="display:none;"><s:date name="trd_d" format="MM/dd/YYYY"/></span><input type="text" size = "8" class="dateFilter" value="<s:date name="trd_d" format="MM/dd/YYYY"/>"/></td>
<td><s:select theme="simple" name="list1[%{rowStatus.index}].vari_ty" id="tranType" list="liTTypes" headerKey="None" value="vari_ty" listKey="key1" listValue="value1" /></td>
<td><span style="display:none;"><s:property value="description"/></span><input type="text" size = "8" value="<s:property value="description"/>"/></td>
<td><s:property value="getText('format.money',{quantity})"/></td>
<td><span style="display:none;"><s:property value="getText('format.money',{price})"/></span><input type="text" size = "10" value="<s:property value="getText('format.money',{price})"/>"/></td>
</tr>
</s:iterator
The second way i tried values not getting bound:
<s:iterator value="list1" var="sVO" status="rowStatus">
<tr onclick="SelIndex('<s:property value="itm_id"/>');">
<td><s:property value="itm_id"/></td>
<td><s:date name="proc_d" format="MM/dd/YYYY"/></td>
<td><span style="display:none;"><s:property value="pln_n_n"/></span>
<input type="text" name="list1[%{#rowStatus.index}].pln_n_n" value="<s:property value="pln_n_n"/>"/></td>
<td><span style="display:none;"><s:date name="trd_d" format="MM/dd/YYYY"/></span>
<input type="text" size = "8" name="list1[%{#rowStatus.index}].trd_d" class="dateFilter" value="<s:date name="trd_d" format="MM/dd/YYYY"/>"/></td>
<td><s:select theme="simple" name="list1[%{rowStatus.index}].vari_ty" id="tranType" list="liTTypes" headerKey="None" value="vari_ty" listKey="key1" listValue="value1" /></td>
<td><span style="display:none;"><s:property value="description"/></span>
<input type="text" name="list1[%{#rowStatus.index}].description" size = "8" value="<s:property value="description"/>"/></td>
<td><s:property value="getText('format.money',{quantity})"/></td>
<td><span style="display:none;"><s:property value="getText('format.money',{price})"/></span>
<input type="text" name="list1[%{#rowStatus.index}].price" size = "10" value="<s:property value="getText('format.money',{price})"/>"/></td>
</tr>
</s:iterator>
Below is the action class that i have
public class testAction extends BaseAction
{
private List<ProcessVO> list1 = null;
// getters and setters for list1
public String ListPage() throws AppException
{
String strReturn = "SUCCESS";
// This the method from which the list1 is populated }
public String ListPageSave() throws AppException
{
String strReturn = "SUCCESS";
// This the method where i need the updated values from list1
// values are not getting bound when this method is called from the page which is having Iterator tag,
}
}
BaseAction:
public class BaseAction extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware, ServletContextAware {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* HTTP Request object.
}
The ProcessVO
contains the attributes and getters and setters for each attribute.
Can anyone please let me know what is the issue here. I am using the same list1 object which needs to be updated. Any help will be very useful for me as i am stuck with this issue.
Upvotes: 1
Views: 2237
Reputation: 50203
<input type = "text" name = "list1[%{#rowStatus.index}].pln_n_n" value = "<s:property value="pln_n_n"/>"/>
If you use HTML tags, OGNL won't work inside them.
You need to either use <s:property/>
:
<input type = "text"
name = "list1[<s:property value="%{#rowStatus.index}"/>].pln_n_n"
value = "<s:property value="pln_n_n"/>"/>
or use Struts2 Tags, where OGNL works:
<s:textfield name = "list1[%{#rowStatus.index}].pln_n_n"
value = "pln_n_n" />
Side notes:
value
is not needed if it's not different from name
, and "SUCCESS"
is against the convention, it should be "success"
(mapped by the SUCCESS
constant)Upvotes: 2