Announcement Announcement Module
No announcement yet.
Dynamic collections in forms Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamic collections in forms

    Hi everyone and thanks for a very informative board

    Being relatively new with Spring I've run into a problem that I so far have not been able to solve. I'm building a FormWizard that will stretch over several jsp-pages, and some of the data entered in one page of the wizard will dynamically create objects that will need to be completed with information in the next page of the wizard.

    The problem I'm having is to iterate over the dynamically created collection of objects, and properly bind them using the spring tag. The following piece of code is how it looks currently:

    <c:forEach var="division" items="${leagueForm.league.divisions}">
    <spring:bind path="">
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>

    The league object in the form contains a collection of division objects, and each division object has a simple get/setName method. Just printing the contents of each division object without using Spring works fine, but the binding process is beyond me. Does anyone know how to perform this type of binding on objects in a collection, where the amount of objects vary?

    Any information or references to other sources would be very appreciated!


  • #2


    • #3
      You need to do something like this:

      <c&#58;forEach var = "division" items = "$&#123;leagueForm.league.divisions&#125;" varStatus = "loopStatus">
        <spring&#58;bind path="leagueForm.league.divisions&#91;$&#123;loopStatus.index&#125;&#93;.name">
          <input name="<c&#58;out value="$&#123;status.expression&#125;"/>" value="<c&#58;out value="$&#123;status.value&#125;"/>" type="text" size="40" />