Announcement Announcement Module
No announcement yet.
Help using formCheckboxes FreeMarker macro in Spring MVC Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help using formCheckboxes FreeMarker macro in Spring MVC

    I am using the following macro in my FTL code:

    <@spring.formCheckboxes "location.color", colorMap, "<br>", 'id="color"'/>

    The colorMap is a TreeMap that is created in referenceData as follows:

    protected Map referenceData(HttpServletRequest request) throws Exception {
    Map m = new HashMap();

    Map colorMap= new TreeMap();
    colorMap.put("red", "Red");
    colorMap.put("yellow", "Yellow");
    m.put("colorMap", colorMap);

    return m;

    However before this page loads I get the following error:

    javax.servlet.ServletException: Expected collection or sequence. list evaluated instead to freemarker.template.SimpleScalar on line 286, column 16 in spring.ftl.

    According to the documentation, formCheckBoxes uses a map just like formSingleSelect . Am I doing something wrong? Thanks for your help.

    -Nalin Mittal

  • #2
    Hi Nalin,

    I have the exact same error. Did you ever sort out what was doing this?



    • #3
      re:Help using formCheckboxes FreeMarker macro in Spring MVC

      I was having a similar problem, except with the freemarker macro formSingleSelect.

      <@spring.formSingleSelect 'purchase.fundType', fundtypes />
      My referenceData method created a hashmap and passed it back to the freemarker page like so:

      protected Map referenceData(HttpServletRequest request, int page) throws ServletException {
      		  Map fundTypes = new  HashMap();
      		  fundTypes.put("noyear", "No Year Funds");
      		  fundTypes.put("multiyear", "Multi Year Funds");
      		  fundTypes.put("annual", "Annual Funds"); 
      		  fundTypes.put("naf", "Non-Appropriated Funds (Same as NAF)");
      		  Map m = new HashMap();
      		  m.put("fundtypes", fundTypes);
      		  return m;
      However when trying to load the freemarker template page I was getting the same error:
      javax.servlet.ServletException: Expected collection or sequence. list evaluated instead to freemarker.template.SimpleScalar

      It seems that it is a configuration issue, with how to setup freemarker to work with Maps, see:

      I couldn't figure out an easy way to change the xml configuration for the spring servlet with just a properties setting, so I extended the FreeMarkerConfigurer to do some post processing to set an objectWrapper with the simpleMapWrapper property to true.

      public class FreemarkerConfiguration extends
      		org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer {
      	freemarker.ext.beans.BeansWrapper objectWrapper;
      	public freemarker.ext.beans.BeansWrapper getObjectWrapper() {
      		return objectWrapper;
      	public void setObjectWrapper(freemarker.ext.beans.BeansWrapper objectWrapper) {
      		this.objectWrapper = objectWrapper;
      	 * After configuration we change the bean wrapper to our custom one that
      	 * will allow us set the simpleMapWrapper to true to enable us to pass
      	 * hashmaps properly to freemarker without it complaining about extra
      	 * methods : see :
      	 * for an explanation of what we are trying to do.
      	protected void postProcessConfiguration(Configuration config)
      			throws IOException, TemplateException {
      Spring Servlet configuration of freemarker:
      <bean id="freemarkerConfig"
      		<property name="objectWrapper">
      			<bean class="freemarker.ext.beans.BeansWrapper">
      				<property name="simpleMapWrapper" value="true" />
      		<property name="templateLoaderPath" value="/freemarker/" />
      		<property name="freemarkerSettings">
      				<prop key="url_escaping_charset">UTF-8</prop>
      After that I could then use freemarker macro formSingleSelect with a hashmap passed from my referenceData method. I suspect that your problem was similar to this?


      • #4
        Thanks Rel for your code on Objectwrapper

        I was searching on how to set the Objectwrapper and your code helped me a lot !

        Thanks once again!