Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'

like image 941
zax Avatar asked May 16 '11 07:05

zax


1 Answers

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:

  • 16.2.4.10 The option tag
like image 143
Sean Patrick Floyd Avatar answered Oct 18 '22 05:10

Sean Patrick Floyd