May 2015
Intermediate to advanced
234 pages
4h 18m
English
In this recipe, you will learn how to display a select field. When the form is submitted, retrieve the selected value in a controller method.
@ModelAttribute method returning a Map object that contains the select field options:@ModelAttribute("countries")
public Map<String, String>countries() {
Map<String, String> m = new HashMap<String, String>();
m.put("us", "United States");
m.put("ca", "Canada");
m.put("fr", "France");
m.put("de", "Germany");
return m;
}String attribute of the default object (refer to the Setting a form's default values using a model object recipe) initialized with one of the Map keys:user.setCountry("ca");form:select ...Read now
Unlock full access