This should be very basic but I can\'t find anything about it in the web, just bits and pieces that I don\'t seem able to fit together..
We\'re using Spring MVC with
According to the docs for formSingleSelect:
@param options a map (value=label) of all the available options
I think your best bet is to provide a map with the values as keys and labels as map values. Otherwise freemarker will probably try to do that wrapping for you and you have less control.
I have just validated: if you supply your own map everything is just fine.
<spring.formSingleSelect "target.property" referenceToYourMapProvidedInController ""/>
After much rephrasing and rethinking I finally discovered the solution:
First
I need to have a bean hold my choice obviously
Second
The options need to be initialized as a String list and provided by Spring MVC to the page:
public ModelAndView get() {
// ...
ModelAndView mav = new ModelAndView();
List<String> options = Arrays.asList(getOptionsFromDatabaseAndConvertToStringList());
mav.addObject("options",options );
mav.setViewName("someview");
return mav;
}
Third
options
now need to be bound in the freemarker template and can then be accessed like any other freemarker variable (i.e. NO quotation marks):
<@spring.bind "options" />
<form action="whatever" method="POST">
<@spring.formSingleSelect "targetBean.choice", options, " " />
<input type="submit" value="submit"/>
</form>