title: Displaying Spring MVC validation errors in Freemarker templates
body: <p>I'm trying to display a list of global validation errors in my freemarker template if a controller returns binding errors. I can display errors that are associated with a field, but I want to detect when an error has occurred within a specific bean and display a message at the top of the page. I've tried using the example below which produces no output: </p>
  
  <pre><code>&lt;@spring.bind "webPage" /&gt;
  ....
  &lt;#if spring.status.error&gt;
  There were problems with the data you entered:
  &lt;ul&gt;
  &lt;#list spring.status.errorMessages as error&gt;
  &lt;li&gt;${error?html}&lt;/li&gt;
  &lt;/#list&gt;
  &lt;/ul&gt;
  &lt;/#if&gt;
  </code></pre>
  
  <p>The line below always returns 0, despite there being errors with the submitted form:</p>
  
  <pre><code>${spring.status.errorMessages?size}
  </code></pre>
  
  <p>My controller code is below:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public ModelAndView save(@ModelAttribute("webPage") @Valid WebPage page, BindingResult result, Model model) {
      if (!model.containsAttribute("site")) {
          throw new IllegalArgumentException("Model must contain site attribute.");
      }
      Site site = (Site) model.asMap().get("site");
      if (!result.hasErrors() &amp;&amp; !page.isNew()) {
          this.pageService.save(page, site);
      } else if (!result.hasErrors() &amp;&amp; page.isNew()) {
          this.pageService.create(page, site);
      } 
      return createMav(result);
  }
  </code></pre>
  
  <p>The createMav method is below:</p>
  
  <pre><code>public ModelAndView createMav(BindingResult result) {
      ModelAndView mav = new ModelAndView();
      mav.setViewName(getPrimaryControllerView());
      mav.addAllObjects(result.getModel());
      return mav;
  }
  </code></pre>
  
  <p>Is there a way to achieve this using Freemarker + Spring MVC?</p>