I'm having some trouble with a converter in a Spring MVC project (version 3.0.6) running on top of Hibernate 3.6.6. I have a custom object "ActionPlan" which has a plan owner and a list of plan users, all of whom are represented by "PlanUser" objects. The relevant portions of the ActionPlan object are as follows:
The Controller for my edit form is loading a converter as follows:Code:@ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "plans_users", joinColumns = @JoinColumn(name = "plan_id"), inverseJoinColumns = @JoinColumn(name = "user_id")) private Set<Planuser> planUsers = new LinkedHashSet<Planuser>(); @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "plan_owner_id") private Planuser planOwner;
Finally, the relevant portion of my edit form is as follows ("userList" is set in the controller as a complete list of all available PlanUser objects from the database):Code:@InitBinder public void initBinder(WebDataBinder binder) { ... binder.registerCustomEditor(PlanUser.class, new PlanUserEditor()); ... } private class PlanUserEditor extends PropertyEditorSupport { @Override public void setAsText(String text) { if(StringUtils.isEmpty(text)) { setValue(null); } else { PlanUser user = new PlanUser(); user.setUserID(Integer.parseInt(text)); setValue(user); } } @Override public String getAsText() { if(this.getValue() == null || !(this.getValue() instanceof PlanUser) ) { return null; } else { PlanUser user = (PlanUser)this.getValue(); return user.getUserID().toString(); } } }
It seems that the single value planOwner is working just fine - the value comes through and I can set it without any problems. However, when is comes to the planUsers Set, it doesn't seem to be parsing out the individual values. I get the following error message:Code:<tr> <td>Plan Owner</td> <td> <form:select path="planOwner"> <form:options items="${userList}" itemLabel="displayName" itemValue="userID" /> </form:select> </td> </tr> <tr> <td>Plan Users</td> <td> <form:select path="planUsers"> <form:options items="${userList}" itemLabel="displayName" itemValue="userID" /> </form:select> </td> </tr>
Any help would be much appreciated.org.apache.jasper.JasperException: org.springframework.core.convert.ConversionFailedE xception: Unable to convert value "[3]" from type 'java.util.Set' to type 'java.lang.String'; nested exception is org.springframework.core.convert.ConverterNotFound Exception: No converter found capable of converting from 'com.myownbadself.PlanUser_$$_javassist_0' to 'java.lang.String'
Thanks,
Alex


Reply With Quote