Hate to bring this up but after a day of failing to get this to work I could use some help.
I have an "edit user" page where you edit some user properties and assign roles to the user. There is nothing fancy about my user class:
In my JSP I'm using the Spring form tags:Code:public User { private String username; private Set<Role> roles; // get/set stuff ... }
And in my controller I wrote a CustomCollectionEditor as suggested all over the place:Code:<form:select path="roles"> <c:forEach items="${allRoles}" var="role"> <form:option value="${role.id}"><fmt:message key="option.role.${role.name}"/></form:option> </c:forEach> </form:select>
I've stepped through the code and everything seems to be working right, the convertElement() method is doing what I think it's supposed to do, but when the form is displayed the option values are empty!Code:protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { binder.registerCustomEditor(Set.class, "roles", new CustomCollectionEditor(Set.class) { protected Object convertElement(Object element) { Long roleId = null; if (element instanceof Long) roleId = (Long) element; else if (element instanceof String) roleId = Long.valueOf((String) element); return roleId != null ? roleFactory.read(roleId) : null; } }); }
If I write the options myself then ${role.id} outputs the right value.Code:<select id="roles" name="roles" multiple="multiple"> <option value="">Superuser</option> <option value="">Normal User</option> <option value="">Some Other User</option> </select><input type="hidden" name="_roles" value="1"/>
Can anyone see what I'm doing wrong? I've tried everything I can think of. The following forum post and open bug report (From 2006!) are similar and make me wonder if this is still really an open issue?
http://opensource.atlassian.com/proj...rowse/SPR-2633
http://forum.springframework.org/showthread.php?t=29849


Reply With Quote
