Announcement Announcement Module
Collapse
No announcement yet.
Dynamic collections in forms Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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}">
    <tr>
    <td>
    <spring:bind path="division.name">
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>"/>
    </spring:bind>
    </td>
    </tr>
    </c:forEach>

    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!

    Cheers,
    Mathias

  • #2
    See: http://forum.springframework.org/vie...ht=nested+form

    Comment


    • #3
      You need to do something like this:

      Code:
      <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" />
        </spring&#58;bind> 
      
      ....
      
      </c&#58;forEach>

      Comment

      Working...
      X