PiratDrogowy
PiratDrogowy

Reputation: 5

How to bind <form:select multiple="true" ... > to List of enums in command object (Spring MVC)?

Here is my simple test class (command object class)

public class Test {
private List<MyEnum> list;

//setters and getters
}

and here is the part od JSP page:

<form:form ......>
<form:select multiple="true" path="list" items="enumvalues">
</form:form>

I would like to bind all selected items from jsp list to my command object list. What is the best way to do this? I know, that I need to write some custom editors but after some tests I have no idea how to achieve that.

I would be grateful for any help.

Upvotes: 0

Views: 5083

Answers (1)

Grzegorz Rożniecki
Grzegorz Rożniecki

Reputation: 28005

If you have proper access to list in JSP, this should work:

<form:form ...>
  <form:select multiple="true" path="list">
    <form:options />
  </form:select>
</form:form>

P.S. If you want options have different readable name than value, just override enum value's toString() and Spring MVC will magically use it as description.

Upvotes: 1

Related Questions