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 freemarker. Now I want to add a form to my page that allows me to select a value from a predefined list (requires database access in the backend).
My controller:
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ModelAndView get(@PathVariable Integer id) {
// stuff..
ModelAndView mav = new ModelAndView();
mav.addObject("targetObject", new TargetObject());
mav.addObject("options", Arrays.asList("a", "b", "c"));
mav.setViewName("someview");
return mav;
}
I found freemarkers spring support spring.ftl
and it seems I should use <@spring.formSingleSelect>
which I've tried like this:
someView.ftl:
<#import "../spring.ftl" as spring />
<form action="somePath" method="POST">
<@spring.formSingleSelect "targetObject.type", "options", " " />
<input type="submit" value="submit"/>
</form>
So targetObject.type is bound automatically by the macro it seems.
But how do I get my options into a freemarker seequence so that the macro can create the options?
Right now I get:
Expected collection or sequence. options evaluated instead to freemarker.template.SimpleScalar on line 227, column 20 in spring.ftl.
The problematic instruction:
----------
==> list options as value [on line 227, column 13 in spring.ftl]
in user-directive spring.formSingleSelect [on line 53, column 9 in productBase/show.ftl]
----------
I also tried:
<@spring.bind "${options}" />
and more things along those lines but with no success:
freemarker.core.NonStringException: Error on line 48, column 18 in someView.ftl
Expecting a string, date or number here, Expression options is instead a freemarker.template.SimpleSequence
Thank's for any help!