Ok so I\'ve been trying to accomplish multiple selects in Spring MVC for a while and have had no luck.
Basically what I have is a Skill class:
public
tkeE2036: I wonder how you said it worked for you at all? The value of each option is "name", not "id". But then in the convertElement method you treat the received element (which is a name), as if it were the id. My guess is that if you tried to set the value of each option as "id", you would get an empty string as the value of each option, because you are using the wrong PropertyEditor.
I found the above non working. In addition to the things mentioned below i also used the answer in: Spring select multiple tag and binding (simply put overide equals and hashcode). I have also changed initBinder based on the comment above
It took me a lot of time to cope with it so i thought to give a hint to anyone looking the same thing and having the problems i met with.
You need to treat the items attribute as a variable, not just reference the variable name:
<form:select multiple="true" path="skills">
<form:options items="${skillOptionList}" itemValue="name" itemLabel="name"/>
</form:select>
put ${skillOptionList}
instead of skillOptionList
You don't need the custom editors - this is all I do and it copies the values back and forth correctly:
<form:select path="project.resources">
<form:option value="XX"/>
<form:option value="YY"/>
</form:select>
Project class:-
private Set<String> resources;
This is how I add the data in the controller:
Set<String> resources3 = new HashSet<String>();
resources3.add("XX");