I'm using Spring 3.1.0.RELEASE. I have this field in my command object ...
public Set<EventFeed> getUserEventFeeds() {
    return this.userEventFeeds;
}
On my Spring JSP page, I want to display a checkbox list of all possible event feeds, and then have checked checkboxes if the user has one in his set. I want to have some special HTML formatting around each checkbox, so I'm trying ...
<form:form method="Post" action="eventfeeds.jsp" commandName="user">
    ...
        <c:forEach var="eventFeed" items="${eventFeeds}">
        <tr>
            <td><form:checkbox path="userEventFeeds" value="${eventFeed}"/></td>
            <td>${eventFeed.title}</td>
        </tr>
        </c:forEach>
    ...
However, the items aren't getting checked by default if one is in the set. How do I do this? Here is the binder I'm using in my controller class ...
@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.registerCustomEditor(EventFeed.class, new EventFeedEditor());
}
private class EventFeedEditor extends PropertyEditorSupport {
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        setValue(eventFeedsDao.findById(Integer.valueOf(text)));
    }
    @Override
    public String getAsText() {
        return ((EventFeed) getValue()).getId().toString();
    }
}
                Interestingly this works:
<form:checkbox path="services" value="${type}" checked="checked"/>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With