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 7699605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:31:05+00:00 2026-05-31T22:31:05+00:00

I am having issues populating a List of User defined object attributes in Struts2.

  • 0

I am having issues populating a List of User defined object attributes in Struts2.

Here is my example (getters / setters ommitted):

public class Foo { private String attr1; private String attr2;
}

public class Bar { private List foos; }

public class StrutsAction extends ActionSupport { private Bar bar; }

I have code in JSP as follows (extract):

<tr><td><input type="text" name="bar.foos.attr1"/></td><td><input type="text" name="bar.foos.attr2"</td></tr>
<tr><td><input type="text" name="bar.foos.attr1"/></td><td><input type="text" name="bar.foos.attr2"</td></tr>

I need each table row to create 1 foo item in the List with each attribute, however my code creats a new foo object for each attribute when passed through and I end up with 4 foos rather than 2!

I understand I can solve the problem with hard coding the Index into the html as follows:

<tr><td><input type="text" name="bar.foos[0].attr1"/></td><td><input type="text" name="bar.foos[0].attr2"</td></tr>
<tr><td><input type="text" name="bar.foos[1].attr1"/></td><td><input type="text" name="bar.foos[1].attr2"</td></tr>

I was wondering if it can be done without hard coding the Indexes?

  • 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-31T22:31:07+00:00Added an answer on May 31, 2026 at 10:31 pm

    I think you can use the Struts 2 iterator tag:

    <s:iterator var="foo" value="bar.foos">
       <tr><td><s:property value="attr1"/> .....
    </s:iterator>
    

    If it does not work, we can think in other solution.

    You can find more information here: http://struts.apache.org/2.3.1/docs/iterator.html

    []s

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

Sidebar

Related Questions

I am having issues populating a dropdown list with a JSON List. Here is
I'm having issues while populating a combobox using DirectStore, the combobox is as follow:
Having issues displaying some websites within iframes. Live example of code This one works.
I have code I am working on, but I am having issues populating the
Having issues with dynamically creating <select> tags and then populating them with XML values.
I am having some trouble populating a large plist into an array. Here is
I'm having some weird issues with dynamically populating a table in Javascript. Behold the
im having issues with the following interface and a class: public interface IRelated {
I am having issues understanding the algorithm. Here is the most popular one seen
Im having issues with accessing the value of a variable in NodeJS. Here is

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.