Reputation: 435
I have a JSP in which I am iterating over a list and creating an editable table.
<s:iterator value="test" id="countryList">
<tr>
<td><s:textfield name="countryCode" value="%{countryCode}" theme="simple" /></td>
<td><s:textfield name="countryName" value="%{countryName}" theme="simple" /></td>
</tr>
</s:iterator>
My list:
List<Country> test = new ArrayList<Country>();
Country class:
public class Country {
private String countryCode;
private String countryName;
and the getter setters......
and say I populate the list like:
Country country = new Country();
Country country1 = new Country();
country.setCountryCode("1");
country.setCountryName("India");
country1.setCountryCode("2");
country1.setCountryName("US");
test.add(country);
test.add(country1);
Now when I change the values of countrycode
and countryname
in the JSP, I should get the updated values in my action. But am I not able to. Is there any way to get these updated values.
Upvotes: 1
Views: 2603
Reputation: 1
You need the Country
object is created when the params
interceptor is populating your list using indexed property access.
<s:iterator value="test" id="countryList" status="stat">
<tr>
<td><s:textfield name="countryList[%{#stat.index}].countryCode" value="%{countryCode}" theme="simple" /></td>
<td><s:textfield name="countryList[%{#stat.index}].countryName" value="%{countryName}" theme="simple" /></td>
</tr>
</s:iterator>
To let the struts populate the list you should use a type conversion annotation or equivalent in the xml configuration.
@Element(value = Country.class)
@Key(value = String.class)
@KeyProperty(value = "countryCode")
@CreateIfNull(value = true)
private List<Country> countryList = new ArrayList<Country>;
Upvotes: 2