PDA

View Full Version : Binding objects in collection in command objects


harry_m
Feb 9th, 2006, 12:17 PM
hi all,
i am new to spring mvc. i need some help on binding a DTO inside command to jsp. scenario is - i have an arraylist in command object that contains list of DTOs. they have some data like gender, title etc . i need to show these when form loads. user can change these values and i need to get them in my controller. so, binding shud be with DTOs inside arraylist.

i am able to display these values but when user changes, they are not getting reflected in controller.

here is code in jsp -

<c:forEach items="${command.arrListAdditionalPassengers}" varStatus="loopStatus" >
<spring:bind path="command.arrListAdditionalPassengers[${loopStatus.index}].ageGroup">
<input type=text value='<c:out value="${status.value}" />' />
</spring:bind>
<br>
</c:forEach>

Pls help.
Thanks in advance.

Colin Yates
Feb 9th, 2006, 12:36 PM
Try http://forum.springframework.org/showthread.php?t=17646&highlight=checkboxes
and http://forum.springframework.org/showthread.php?t=20503&highlight=checkboxes

You will find the information relevant even though you are not using checkboxes :)

harry_m
Feb 10th, 2006, 05:15 AM
hi,
Problem solved. I was missing name binding to status.expression.
Read in a book that thru status.expression, spring binds control on html to corresponding elements in command object.
Here is the correct code thats working for me -

<c:forEach items="${command.arrListAdditionalPassengers}" varStatus="loopStatus" >
<spring:bind path="command.arrListAdditionalPassengers[${loopStatus.index}].ageGroup">
<input name='<c:out value="${status.expression}" />' type=text value='<c:out value="${status.value}" />' />
</spring:bind>
<br>
</c:forEach>

bye.