Here's the tag in my jsp
<form:checkboxes itemValue="value" itemLabel="label" path="user.degrees" items="${degreeLabels }" />
Here's the way I populated my model map to retain ordering. (I placed this code in my FormController's referenceData method)
List labelValues = new ArrayList<LabelValue>(); for (Degree d : Degree.values()) { labelValues.add(new LabelValue(d.name(), d.name())); } Map model = new HashMap(); model.put("degreeLabels", labelValues);
You can see from the path on my tag that degrees is a property on my User object...which is the target of my form. Here's what that looks like...I threw in my Hibernate annotations for the curious:
private Set<Degree> degrees = new HashSet<Degree>(); @CollectionOfElements @Enumerated(EnumType.STRING) public Set<Degree> getDegrees() { return degrees; } public void setDegrees(Set<Degree> degrees) { this.degrees = degrees; }
public enum Degree { BA,BS,BN,BSW,MA,MS,MBA,MSN,MSW,MD,JD,PhD,PharmD,PsyD,Other;}