I want to create a drop down menu that allows a client to search users by a field specified in the drop down menu. For example, search by state, search by city, etc.
Because the accepted answer is not using Thymeleaf and this question is top in Google I'm adding my solution here.
In my situation statues
is a list of Enum values. Model attribute is populated as usually you do in Spring:
mav.addObject("statuses", EnumSet.allOf(Status.class));
Group has a filed of type Status (the enum).
<div class="form-group row">
<select class="form-control" id="status" name="status">
<option th:each="stat : ${statuses}"
th:value="${stat}"
th:text="${stat}"
th:selected="${stat.equals(group.status)}"/>
</select>
</div>
This automatically populates the list and selects value that is selected in my Group instance:
You have just the required answer in this link:
http://fruzenshtein.com/spring-mvc-form-select-tag/