In Listing 8-27 we show an example Controllerthat puts options for the grouped form
input fields into a Mapnamed options. Listing 8-28 shows a template that displays the same set
of options as both a single select drop-down list and a group of check boxes. Lastly in Listing
8-29 we show the HTML that will be rendered from the template.
Listing 8-27.Setting the Options Map in a Controller
public ModelAndView handleRequest(...) {
Map model = new HashMap();
Map<String, String> options = new HashMap<String, String>();
options.put("NYC", "New York City");
options.put("LON", "London");
options.put("PAR", "Paris");
model.put("options", options);
return new ModelAndView("cityForm", options);
}
Listing 8-28.Displaying the Options in the Template
<!-- can only select one here! -->
#springFormSingleSelect("command.city" $options "")
<br>
<!-- can select more than one here -->
#springFormCheckboxes("command.city" $options "<br>" "")
Listing 8-29.HTML Output from the Grouped Input Macros
<!-- can only select one here! -->
<select name="city" >
<option value="LON"
>
London</option>
<option value="NYC"
>
New York City</option>
<option value="PAR"
>
Paris</option>
</select>
<br>
<!-- can select more than one here -->
<input type="checkbox" name="city" value="LON"
> London <br>
246 CHAPTER 8 ■SUPPORTED VIEW TYPES