i'm trying to create a listbox where the user will be able to selct multiply values. My view is this:
View:
<td>
<form:label path="role">Role:</form:label></td>
<td>
<select name="role" multiple="true">
<OPTION VALUE="admin">admin</OPTION>
<OPTION VALUE="user">user</OPTION>
</select>
</td>
Model:
.
.
fields
.
private ArrayList<Role> role;
get/set
the Role class:
public class Role {
private String role;
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
So according to this post http://stackoverflow.com/questions/3...eckboxes-issue, i create a new class which is the following:
public class RoleEditor extends PropertyEditorSupport {
@Override
public String getAsText() {
return ((Role) getValue()).getRole();
}
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(text);
}
}
And finally in the controller class i add this:
@InitBinder
@RequestMapping(value = "/log", method = RequestMethod.POST)
public String setRegistrationForm(@ModelAttribute("logAtr") Register register,
Registration registration,Model model,HttpSession session,WebDataBinder b) {
b.registerCustomEditor(Role.class, new RoleEditor());
.
.
return "aView"
}
But i still take this exception: Cannot convert value of type [java.lang.String[]] to required type [java.util.ArrayList] for property 'roles': no matching editors or conversion strategy found]
I try to follow the example which seems to be correct but the problem didn't solve. What i'm doing wrong?


Reply With Quote
