PDA

View Full Version : Multi checkbox... again


shoa
Aug 13th, 2006, 05:39 AM
Hello

I want to use checkboxes for selecting in my application and find out a way to do that as the following:

=========================================
<c:forEach items="${command.childArray}" var="child" varStatus="loopStatus">
<spring:bind path="command.childArray[${loopStatus.index}].selected">
<input type="hidden" name="_<c:out value="${status.expression}"/>">
<input type="checkbox" name="<c:out value="${status.expression}"/>" value="true"
<c:if test="${status.value}">checked</c:if>/>
</spring:bind>
</c:forEach>
========================================

It can be seen that to use this way, the objects (for selecting) must be in an array (childArray). So I can have:

<spring:bind path="command.childArray[${loopStatus.index}].selected">

What I have to do if it is a list - not an array ???.

I tried:

<spring:bind path="command.objectList.get(loopStatus.index).selected">

But it does not work

Thanks for any help
sho

gmatthews
Aug 13th, 2006, 07:24 PM
having Integer[] selectedItems in your command with getter/setters and then in the JSP doing the following works.

<c:forEach items="${items}" var="item">
<form:checkbox path="selectedItems" value="${item.id}"/>
</c:forEach>

No need for indexes, etc.

This uses the Spring 2.0 form taglib.

shoa
Aug 13th, 2006, 07:36 PM
However, my one is only 1.2.7 - it is a workgroup project - hard to change the verson of the spring
Regards

jglynn
Nov 29th, 2006, 02:58 PM
having Integer[] selectedItems in your command with getter/setters and then in the JSP doing the following works.

<c:forEach items="${items}" var="item">
<form:checkbox path="selectedItems" value="${item.id}"/>
</c:forEach>

No need for indexes, etc.

This uses the Spring 2.0 form taglib.

Excellent post gmatthews.