Showing posts with label spring bind collection checkbox. Show all posts
Showing posts with label spring bind collection checkbox. Show all posts

Tuesday, May 12, 2009

Spring bind collection to checkbox

Here is an example in JSP to bind a collection as checkboxes with spring form:checkbox.

<c:forEach varStatus="status" var="product" items="${command.products}">
<form:checkbox path="products[${status.index}].productId" value="${product.id}" />
</c:foreach>

Note the command will always have the collection "products". However, the selected ones - the ones with checkbox checked, will have valid "id" values. This is the way to tell which ones are selected.