Multiple Select in Spring 3.0 MVC

后端 未结 4 1004
太阳男子
太阳男子 2020-12-08 01:21

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         


        
相关标签:
4条回答
  • 2020-12-08 01:41

    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.

    0 讨论(0)
  • 2020-12-08 01:58

    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.

    0 讨论(0)
  • 2020-12-08 01:59

    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

    0 讨论(0)
  • 2020-12-08 02:01

    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");
    
    0 讨论(0)
提交回复
热议问题