Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7499987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:00:56+00:00 2026-05-29T20:00:56+00:00

I am validating list of objects. In order to show users what they typed

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:00:58+00:00Added an answer on May 29, 2026 at 8:00 pm

    It’s better if you ask how to do something… rather than say you have a reason for doing it this way and of course this way isn’t working. It gives me a headache…

    I don’t understand this…

    <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’ll rewrite (without testing) what I think you mean…

    <s:iterator value="users">
       <s:textfield name="users.birthdate" value="birthdate"/>
    </s:iterator>
    

    The above requires that the following conditions be met… a) That “users” is a list of type “User” and b) that the struts2 conversion framework has been told that users is a list of type “User” which is as simple as adding an annotation like so: http://struts.apache.org/2.3.1.2/docs/keyproperty-annotation.html

    With those conditions met… Send as many at one time without the mess of needing to use array notation and you can repopulate the fields.

    Now, why would you expect the form values to repopulate after it failed to submit? That is how are you using validation? If for some reason you aren’t you have created some action mapping on a value of INPUT or ERROR to direct back to the input page (kind of a waste of effort when the validation framework exists).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have a list of financial transactions, I have a need to execute
I am working on a process for validating documents to make sure that they
I am binding a list of objects to a select using knockout. Object Class
I've got a list of Validation objects - validations. public class Validation { public
I've got a list of Definition objects (definitions), each Definition object has a list
I'm working with Steve Sanderson's BeginCollectionItem utility to render a list of objects to
I need to test if some objects inside a database fill a specific range,
I'm trying to implement a custom validation annotation in Seam. We have a list
Validating Primitive Arguments and Complex Data Validating Arguments When writing a method, arguments should
When validating user inputs in an application that is to be run across multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.