I am validating list of objects. In order to show users what they typed wrong, I need to repopulate fields on conversion error. I read that in order to repopulate fields value on page I need to do something like this:
<s:textfield name="user.name" value="%{user.name}"/>
For repopulating array, I must refer to them through indices. As mentioned here: update a list of value in textfield in struts2
I have a list of Users, that I need to validate. I have my own index counter on iterator for specific reason.
<s:set name="counter" value="0"/>
<s:iterator value="users" var="user">
<s:textfield name="users[%{#counter}].birthdate" value="%{users[#counter].birthdate}"/>
<s:set name="counter" value ="%{#counter + 1}"/>
</s:iterator>
I am using visitor validator for object User.
<field name="birthdate">
<field-validator type="conversion">
<param name="repopulateField">true</param>
<message>${getText("E011", {"birthdate"})}</message>
</field-validator>
</field>
As I said, I am not using iterator index counter for specific reason.
The problem is this value="%{users[#counter].birthdate}"
part is not working. If I change counter
to 0
it repopulates the value of users[0].birthdate right. Seems like it is not getting value of counter in OGNL expression.
I tried with:
value="%{users[counter].birthdate}"
value="%{users[%{#counter}].birthdate}"
...
and so on.
Can somebody help me to make this work?
UPDATE
It ended up that I should have mentioned my special case:
<s:iterator value="users" var="user" status="status">
<s:if test="#status.index != removeIndex">
I found out that I don't need to specify value for field name for it to repopulate values. But I needed to use that because of this line:
<s:if test="#status.index != removeIndex">
It will take lots of my English effort to explain why you guys misunderstood me. Can we delete this post?. Thanks