I need to populate a drop down with all the values within a list of strings.
Controller Class
@RequestMapping(value = "/generateIds", method = RequestMethod.GET)
public String launchPage(Model model) {
List<Municipality> municipalities = rCountryService.finaAllMunicipalities();
//assume the list is populated with values
List<String> countryName = new ArrayList<String>();
for(int i=0; i<municipalities.size(); i++) {
countryName.add(municipalities.get(i).getCountry().toString());
}
model.addAttribute("countryName ", countryName );
return "generateIds";
}
I didn't know where to start for the HTML so I started with this
<select th:field="*{countryName }">
<option value="default">Select a country</option>
<option th:each="${countryName }" th:value="${countryName }"th:text="${countryName }"/>
</select>
What should my html/controller look like to add all of the elements of the list as drop down options?
Thanks in advance!