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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:59:03+00:00 2026-05-27T19:59:03+00:00

I am developing a registration web app using Struts2 and need some guidance. Background:

  • 0

I am developing a registration web app using Struts2 and need some guidance.

Background:

On the registration form, there is a set of five form fields: 1 text box, and 4 drop down select boxes. The five fields describe a person’s primary position in an educational setting: the text field allows the user to insert their job title, and the drop down menus allow the user to select what school, institution, department, and division they belong to. The drop down menus are initialized with options that are stored in a database (inside the registration action, array lists are initialized with these values before the form is displayed). For example:

<s:select emptyOption="true" key="school1.schoolId" list="schoolList" listKey="schoolId" listValue="schoolName" required="true" />

Problem:

I need to provide the user with the ability add an X number of secondary positions. On the registration form, a user can click an “add another affiliation” button, and a new set of the 5 form fields are displayed. These fields will also need to be validated, and saved when the user clicks the form’s submit button.

What would be the best approach to tackling this problem?

So far, I have only declared array lists for each form field, like so:

private List<String> jobTitles = new ArrayList<String>();
private List<School> schools = new ArrayList<School>();
private List<Institution> institutions = new ArrayList<Institution>();
private List<Department> departments = new ArrayList<Department>();
private List<Division> divisions = new ArrayList<Division>();

But I do not know how to proceed. How do I display the initial 5 fields for the primary position? If I use Javascript to insert new form fields dynamically, how do I initialize the dynamic drop down menus with the options stored in the database? How do I retain these values if the page is reloaded?

Any help is appreciated – 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-27T19:59:03+00:00Added an answer on May 27, 2026 at 7:59 pm

    The basic problem you need to tackle is how to get an indexed list of request parameters into your action class. This is quite simple, and I think you are on the right track by starting off by creating Lists of input parameters. I found a bit of documentation on the subject here. Basically you can have form fields with names like jobTitles[0], jobTitles[1] which would be used to populate the jobTitles List.

    However, I think the concept of ‘Affiliation’ deserves a class of it’s own:

    class UserAffiliation {
       private String title;
       private String schoolId;
       private String institutionId;
       private String departmentId;
       private String divisionId;
    
       // Make sure that there is a no-args constructor (default or explicit) for Struts to create instances. 
       // Add getters and setters
    }
    

    In your action class:

       private List<UserAffiliation> affiliations;
       ...
       // getter and setter for affiliations
    

    Would be enough to capture the user input.

    Your jsp could look something like:

    <form action=".." method="post">
      <div class="affiliation">
         <s:textfield name="affiliations[0].title"/>
         <s:select name="affiliations[0].schoolId" list="schools" listKey="schoolId" listValue="schoolName"/>
         ...
      </div>
    
      <s:if test="affiliations != null && affiliations.size > 1">
        <s:iterator value="affiliations" begin="1" status="status">
            <s:textfield name="affiliations[%{#status.index + 1}].title"/>
            <s:select name="affiliations[%{#status.index + 1}].schoolId" list="schools" listKey="schoolId" listValue="schoolName"/>
                ...
        </s:iterator>
      </s:if>
      ....
    </form>
    
    <div id="affilationTemplate" style="display:none;">
       <div class="affiliation">
          <s:textfield name="affiliations[__IDX__].title"/>
          <s:select name="affiliations[__IDX__].schoolId" list="schools" listKey="schoolId" listValue="schoolName"/>
       </div>
       ...
    </div>
    

    Note the div affilationTemplate. You could use JS to get the html of this template, replace __IDX__ with the appropriate index, and append to the form contents when the user clicks on the ‘add another affiliation’ button. This makes sure that the newly added select boxes are pre-populated with appropriate values.

    The iterator block displays what ever the values the user had already submitted (with the exception of the ‘primary affiliation’, which is already displayed above it).

    NOTE: You should of course, try to get rid of the repeated form elements if possible. I would try with extracting them into an include.

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

Sidebar

Related Questions

I am developing a student registration form in asp.net. there are two tables viz
Currently I'm developing a registration form for new user in Android (native app.) and
I am Developing a Registration Form in ASP.NET in Which I am using client
I'm developing a Rails App and am using Devise for authentication. For some odd
Developing a project of mine I realize I have a need for some level
I'm developing a website with using struts2 and jsp pages. In many sites after
i´m developing a Facebook Fanpage using PHP-SDK 3.0 and integrated a Facebook Registration Plugin.
I'm developing an iPhone app that needs a web login. As usual I call
I am developing a new web application with Struts2, Spring and Hibernate as its
I've been thinking about the web app I'm about to begin developing and wondering

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.