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

  • Home
  • SEARCH
  • 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 6201113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:29:42+00:00 2026-05-24T04:29:42+00:00

I’m looking for a good design pattern/strategy for how to using the Struts 2

  • 0

I’m looking for a good design pattern/strategy for how to using the Struts 2 framework for editing multiple objects of the same type on an HTML page. Struts is really good for editing a single object, like Address. If you provider accessor methods for address1, city, state, etc, struts calls those and the standard struts UI tags will populate the form fields accordingly.

How to do this when editing multiple of the same type of object on the same page. I have a web based contest, parting of the contest is a set of rating scale objects for each contest. Each rating scale has a value and a label. If I name the input fields value_0, value_1… and label_0, label_1… then I either have to code a bunch of accessor methods (UGLY) or use the raw parameters to get the values I need. It is difficult, but not impossible, to use the struts validation methods to send error messages back to the correct form field.

If I name all the fields “Value” and “label”, struts is kind enough to call a method that sets a List of input values, but I have no way of sending validation errors back to the correct output field.

I need something that doesn’t require a huge number of accessor methods, allows easy access to the inputs to validate, return validation messages to the correct form field.

  • 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-24T04:29:42+00:00Added an answer on May 24, 2026 at 4:29 am

    The strategy here is to use a Map<Integer, Address>.

    Example Bean Class

    Let’s assume the following example Address class.

    public class Address {
      private String line1;
      private String line2;
      private String city;
      private String state;
      private String zipCode;
    
      // getters and setters here
    }
    

    Example Action

    public class ExampleAction extends ActionSupport {
      /**
       * A map of ID -> Address.
       */
      private Map<Integer, Address> addresses = Maps.newLinkedHashMap();
    
      // ... action method(s) and validate here
    
      public Map<Integer, Address> getAddresses() {
        return addresses;
      }
    }
    

    In your JSP layer, you can iterate over the map (each iteration is a Map.Entry) and output the fields (line1, line2, city, etc.) for each. The field names should be:

    addresses[0].line1
    addresses[0].line2
    addresses[0].city
    addresses[0].state
    addresses[0].zipCode
    
    ...
    
    addresses[5].line1
    addresses[5].line2
    addresses[5].city
    addresses[5].state
    addresses[5].zipCode
    

    To perform validation, just iterate over the map and check each field appropriately. When editing addresses, you can use the primary key of the address from your database. For adding new addresses, you can just increment starting from zero. The index can be any number, so long as its unique within the map.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have thousands of HTML files to process using Groovy/Java and I need to
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.