How do I retrieve the selected value in a drop down menu in Thymeleaf and have the Spring MVC process it?
Here is my thymeleaf code:
<form style="display:inline-block" th:action="@{/search}"
th:object="${searchOptions}" method="get">
<select id="optionsList" name="optionsListId">
<option th:each="option : ${searchOptions}"
th:value="${option.getOption()}"
th:text="${option.getOptionName()}"
th:selected="${selectedOptionsList.contains(option.getOption())}">Options</option>
</select>
</form>
"searchOptions" is the name of a model attribute which is an ArrayList of SearchOptionobjects.
Here is the SearchOptions class:
package formBeans;
public class SearchOption {
private String option;
private String optionName;
public SearchOption() {
}
public SearchOption(String option, String optionName) {
this.option = option;
this.optionName = optionName;
}
public String getOption() {
return option;
}
public String getOptionName() {
return optionName;
}
public void setOption(String option) {
this.option = option;
}
public void setOptionName(String optionName) {
this.optionName = optionName;
}
}
How do I write the code with spring mvc to retrieve the selected value in the drop down box. I have tried finding examples online and they haven't helped.
Thanks