May 2015
Intermediate to advanced
234 pages
4h 18m
English
In this recipe, you'll learn how to display a list of checkboxes and when the form is submitted, how to retrieve the selected values in a controller method.
@ModelAttribute method returning a Map object:@ModelAttribute("languages")
public Map<String, String>languages() {
Map<String, String> m = new HashMap<String, String>();
m.put("en", "English");
m.put("fr", "French");
m.put("de", "German");
m.put("it", "Italian");
return m;
}String[] attribute of the default object (refer to the Setting a form's default values using a model object recipe) initialized with some of the Map keys:String[] defaultLanguages = {"en", "fr"}; user.setLanguages(defaultLanguages); ...Read now
Unlock full access