I am using Spring 1.1.4 and it binds to a Set just fine right out of the box. My example:
Command object (named criteria in the JSP page):
Code:
// Accessor methods removed for brevity
public class SearchCriteria {
private String searchText;
private long country;
private Set<Long> metros;
JSP page:
Code:
<spring:bind path="criteria.metros">
<select name="${status.expression}" id="metro" size="5" multiple>
<c:if test="${criteria.country != 0}"><option value="0"<xx:ifEmptyIdCol col="${criteria.metros}"> selected</xx:ifEmptyIdCol>>All Locations</option><c:forEach items="${countryMap[criteria.country].metros}" var="metro"><option value="${metro.id}"<xx:ifInIdCol id="${metro.id}" col="${criteria.metros}"> selected</xx:ifInIdCol>>${metro.name}</option></c:forEach></c:if>
</select>
</spring:bind>
Spring automatically binds to the collection (Set or List) with no trouble at all. I have noticed that it seems to like inserting String values into the Set, however. Thus, my processors handle either Long or String values in the collection to avoid any problems. There is also another thread going in which we are discussing using a custom PropertyEditor to handle binding of a Set: http://forum.springframework.org/viewtopic.php?t=2258. You may want to keep an eye on that thread, as I'm sure an example will be posted soon.
The ifInIdCol checks a set/collection for a given ID element, and the ifEmptyIdCol checks if a collection contains no meaningfull values, since I have a placeholder value 0 to indicate All Metros.