Announcement Announcement Module
Collapse
No announcement yet.
yet another question about binding checkboxes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • yet another question about binding checkboxes

    I have a fairly common case here - my backing object - "ConferenceEvent" - has a list of "CategoryDomain" objects attached to it, like so:

    Code:
    public class ConferenceEvent {
    	...	
    	private List<CategoryDomain> categoryDomains;
    	...
    }
    
    public class CategoryDomain {
    	private int id;
    	private String domainName;
    
       ... getters and setters ...
    }
    I want to present a list of checkboxs on an "ConferenceEvent Edit" page showing all available categories, with the categories already selected by the ConferenceEvent checked. When I use the standard form:checkbox tag, everything works great:
    Code:
     <form:checkboxes items="${categoryDomainList}" path="categoryDomains" itemLabel="domainName" itemValue="id" delimiter="<br />" />
    The rub here is that I need a bit more control over formatting and labels (there are some special cases where things should be highlighted or show extra options), so I'd like to use the JSTL foreach. With this code, I do see all of the categories and the selected items are bound to my ConferenceEvent on submit, but the selected items are not checked in my form. Can anyone see what I'm doing wrong here? I've read through a few other posts about binding checkboxes, but none of them have solved this for me.

    Code:
    	<c:forEach items="${categoryDomainList}" var="categoryDomain" varStatus="loopStatus">
    		<spring:bind path="categoryDomains"> 
    				<input type="checkbox" value="<c:out value="${categoryDomain.id}" />" name="${status.expression}" id="categoryDomains<c:out value="${loopStatus.index}" />">
    				<label for="categoryDomains<c:out value="${loopStatus.index}" />">
                                 <c:out value="${categoryDomain.domainName}" /></label>
    		</spring:bind>
    		<br />
    	</c:forEach>
    Thanks,
    Alex
Working...
X