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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:49:02+00:00 2026-05-20T22:49:02+00:00

I have custom Question objects which I render into html form elements. I want

  • 0

I have custom Question objects which I render into html form elements. I want to be able to dynamically create these objects and generate a dynamic html form from them. The question object has a String property to hold the result from the form. How can I get this to work in Spring?

The way I have it working (which doesn’t seem ideal), is I have a bean to back the custom form. This bean has two properties: a List to hold the questions to be displayed and a List to hold the results. The JSP has a tag which tells it to use the bean as a model attribute. Then I have a custom JSP tag that takes the List and renders them into form elements. The elements are given IDs of answer[n] and Spring will put the results of the form into the List property in the backing bean.

Does anyone know how I can do this better?

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

    My problem was a lack of experience.

    I ended up with this (much simplified for explanation):

    My bean has the following fields: String questionType, String questionText, String answer.
    My list of beans is List questions.

    When I generate the HTML from the list of beans, I just need to make the id/name of each form element match up with the name of the list, and the position of the bean within the list.

    So, if my list of questions looks like this:

    [0] {questionType="TEXT", questionText="What is your name?", answerText=null}
    [1] {questionType="TEXT", questionText="What is your quest?", answerText=null}
    [2] {questionType="TEXT", questionText="What is your favorite color?", answerText=null}
    

    Then I need to generate the following HTML when I loop through the list:

    <div class="question">
        <p class="questionText">What is your name?</p>
        <input type="text" id="questions[0].answerText" name="questions[0].answerText" />
    </div>
    <div class="question">
        <p class="questionText">What is your quest?</p>
        <input type="text" id="questions[1].answerText" name="questions[1].answerText" />
    </div>
    <div class="question">
        <p class="questionText">What is your favorite color?</p>
        <input type="text" id="questions[2].answerText" name="questions[2].answerText" />
    </div>
    

    When the form is submitted, Spring will find those beans and call setAnswerText(String value) on them with the form data.

    I hope this helps someone else stumbling at the beginning of their Spring MVC journey.

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

Sidebar

Related Questions

I have question about NSView: Imagine a Custom View where the mouseDown, mouseDrag and
I have this question: Does implementing a custom MembershipProvider class needs you to implement
Coming from this question , I have a wxComboCtrl with a custom popup made
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
hi i would like to create a custom calendar, this calendar will have custom
I have a login.jsp page which contains a login form. Once logged in the
I have custom coded several enterprise applications for mid to large organizations to use
I have custom errors configured in my web.config, but IIS 6.0 is returning the
I have a few models that need to have custom find conditions placed on
I have a custom validation function in JavaScript in a user control on a

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.