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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:48:53+00:00 2026-06-04T02:48:53+00:00

Could someone please help me find out why my attempt to bind Collection to

  • 0

Could someone please help me find out why my attempt to bind Collection to the form in Spring MVC is not working?

Here is how my object looks like –

public class TestObj {
   private Integer testNumber;
   private String home;
   private String destination;
}

Here is my form object that contains list of above object –

public class TestForm {
   private List<TestObj> testList;
   //contains getter and setter for testList
}

In my controller, I have implemented formBackingObject method –

public class MyController extends SimpleFormController {

    public MyController() {
        setCommandClass(TestForm.class);
        setCommandName("testForm");
    }

        protected Object formBackingObject(HttpServletRequest request) throws Exception {
           if (isFormSubmission(request)) {
              testForm = (TestForm) super.formBackingObject(request);
              //THIS ALWAYS RETURNS NULL ON FORM SUBMISSION 
              List<TestObj> testList = testForm.getTestList();
           } else {
              //load initial data using hibernate. TestObj is hibernate domain object.
              List<TestObj> testList = myService.findTestList();
              testForm = new TestForm(testList);
           }
           return testForm;
        }

Here is my JSP snippet –

<form:form commandName="testForm" method="post">
   <c:forEach items="${testForm.testList}" var="testvar" varStatus="testRow">
     <tr>
       <td>
          <form:hidden path="testList[${testRow.index}].home" />
          <c:out value="${testvar.home}" />
    </td>
    <td>
      <form:input path="testList[${testRow.index}].destination" />
    </td>
     </tr>
   </c:forEach>
   <tr><td><input type="submit"></td></tr>
</form:form>

While the first time I load the data shows up fine on the form, when I press submit button the control goes to the formBackingObject method and the isFormSubmission returns true. However, when I get the command object using super.formBackingObject(request), it returns the form object with the testList value as null. I am unable to figure out why this simple case is not working?

I will really appreciate any help in getting this to work.

  • 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-06-04T02:48:54+00:00Added an answer on June 4, 2026 at 2:48 am

    I guess my understanding of formBackingObject method must be wrong. I removed that method from the implementation, used referenceData for initial form load and onSubmit to process it on submit. This works fine and does get collection in the form back as expected.

    Thanks all for the help though.

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

Sidebar

Related Questions

Could someone please help me out with this. I need to find the gml:pos
Could someone please help me in here, I'm just a beginner who want to
Could someone please help me figure out what is wrong with the following code
I was hoping someone could help me sort something out. I've been working on
could someone please help me with this problem, sorry for the Language in the
Could someone please help explain why I can't get this to work? I properly
Could someone please help me with the code for below requirement or scenarios...I achieved
I'm a newbie, could someone please help me what type is the Parts, I
I've recently written this with help from SO. Now could someone please tell me
Please could someone help me understand why the div.fl element shown in Developer Tools

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.