zax
zax

Reputation: 147

Select in Spring MVC by enum

What is way to select enum from database? I have:

<select name="country">
  <c:forEach items="${countries}" var="value">
    <option value="${value}">${value}</option>
  </c:forEach>
</select>

I have in class and table 'User' field string/varchar 'country'

Upvotes: 13

Views: 17228

Answers (1)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298838

Use the option and options tags from the spring forms tld.

If I understand it correctly, you will have to add YourEnum.values() to the model, say as "enumValues" (according to comments below, this is not necessary).

<form:select path="foo">
     <form:option value="-" label="--Please Select"/>
     <form:options items="${enumValues}" />
</form:select>

Reference:

Upvotes: 25

Related Questions