Hi everyone,
I'm currently developing a small Project/ChangeManagement Tool for sure with Spring helping me in many places.
I've now a bean with multiple properties and two Sets of other beans:
To create/edit projects I've a form using Spring MVC and Springs form taglibrary (I love it...together with JSTL it's really great). This form contains to select boxes for the teamMembers and environments:Code:public class ProjectBean extends EntityBean{ private String name; private String description; private UserBean coordinator; private Set<UserBean> teamMembers; private Set<EnvironmentBean> environments; ... some more properties ... accessors }
To convert the Parameters for both sets I need to CustomEditors. I did this for the environments already and it works fine.Code:snip <tr> <td><B>Environments:</B><br></td> <td> <form:select path="environments" multiple="true"> <form:options items="${environments}" itemValue="id" itemLabel="name"/> </form:select> <span class="error-red"><form:errors path="environments"/></span> </td> </tr> <tr> <td><B>Team Members:</B><br></td> <td> <form:select path="teamMembers" multiple="true"> <form:options items="${users}" itemValue="id" itemLabel="fullName"/> </form:select> <span class="error-red"><form:errors path="teamMembers"/></span> </td> </tr> snip
Controller:
Editor:Code:snip public void initBinder(HttpServletRequest request, ServletRequestDataBinder binder){ binder.registerCustomEditor(UserBean.class, new UserPropertyEditor(userManager)); binder.registerCustomEditor(EnvironmentBean.class, new EnvironmentPropertyEditor(environmentManager)); binder.registerCustomEditor(Set.class, new EnvironmentCollectionPropertyEditor(Set.class, environmentManager)); binder.registerCustomEditor(Date.class,new CustomDateEditor( new SimpleDateFormat("dd/MM/yyyy"), true)); } snip
But how can I have two editors for Set.class? One has to take care for the environments as shown above, and the other should take care for the teamMembers? But there's no way to separate the binder Objects? Is there?Code:public class EnvironmentCollectionPropertyEditor extends CustomCollectionEditor { private EnvironmentManager environmentManager; /** * @param collectionType */ public EnvironmentCollectionPropertyEditor(Class collectionType, EnvironmentManager environmentManager) { super(collectionType); this.environmentManager = environmentManager; } protected Object convertElement(Object element){ if(element != null) { Integer id = new Integer((String)element); return environmentManager.getEnvironmentById(id); } return null; } }
I tried to find something here and in the docs (both helped me to get my PropertyEditors to work), but found nothing which suits to my issue.
Cheers,
Thomas



Reply With Quote