Hi people, I'm facing a problem 'cause i cant bind a list with a select multiple html element.
The problem is on the submit of the form, if I select multiple elements from my html form, nothing is submited and my view is rendered another time.
I've created a custom converter: roleToSet to convert strings to set, without success:
I've defined two model class with setters and getters:
User:
and Role:Code:@Entity public class User implements java.io.Serializable { @Id @GeneratedValue private int id; private String name; @ManyToMany(cascade=CascadeType.PERSIST) private Set<Role> role = new HashSet<Role>(0);
i've defined a flow to insert a user: createuser.xmlCode:@Entity public class Role implements java.io.Serializable { @Id private int id; private String name;
and the converter roleToSet:Code:<?xml version="1.0" encoding="UTF-8"?> <flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> <persistence-context /> <on-start> <evaluate expression="userManager.createUser()" result="flowScope.user" /> </on-start> <view-state id="create_user" model="user" > <binder> <binding property="name" /> <binding property="role" converter="roleToSet"/> </binder> <on-render> <evaluate expression="roleManager.allRoles()" result="viewScope.rolesList" /> </on-render> </flow>
the problem is on my SELECT element:Code:public class roleToSet extends StringToObject { public roleToSet() { super(Set.class); } @Override protected Object toObject(String string, Class targetClass) throws Exception { .... } @Override protected String toString(Object object) throws Exception { Role role = (Role) object; return role.getName(); } }
If I select only one element and then i submit the form, the toObject method is called and the object will update to the database correctly.Code:<form:select path="role"> <form:options items="${rolesList}" itemLabel="name"/> </form:select>
If i select multiple elements, it doesn't submit the form, but redirects me the formView instead.
I need some help, i can't figre the problem 'cause no exception is raised


Reply With Quote
