Announcement Announcement Module
No announcement yet.
UTF-8 in AbstractWizardFormController and Freemarker Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • UTF-8 in AbstractWizardFormController and Freemarker

    Hi all,

    I have a little problem here...
    I am using Freemarker templates, and when I use it with an AbstractWizardFormController I come across an encoding problem...

    Let me explain, The first page of the wizard form controller is displayed just fine, it uses UTF-8 because I am telling it to do so (response.setContentType....), the second as well, it is displayed just well (because it is the normal work flow of the controller). But when I am on the second page, I sometimes need to insert fields (in the form) after the user clicks on submit buttons. So when I see the user clicking on those buttons, I just reload the same page adding some more elements to the form, but here comes the problem... The page reloads and all the UTF-8 encoding is GONE... It tells me the page is in ISO-8859-1.

    I though I could try to override the function "processFormSubmission" (of the AbstractWizardFormController) to force the response to be UTF-8 at all time, but that function is final... And I haven't found anything else...

    Maybe somebody has a good idea? That would be amazing!


  • #2
    I always add accept-charset="utf-8" to my form tags:
    <form action="..." accept-charset="utf-8">
    You might also want to make sure that your Freemarker Configuration bean has the "defaultEncoding" property set to UTF-8:
    <bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    <property name="defaultEncoding" value="UTF-8" />
    And lastly, are you using Spring's CharacterEncodingFilter?


    • #3
      Sorry I took my time to answer...
      SO yes I am using that already, but what I did to fix everything is to create a new filter and to reset everything to UTF-8 on all responses...

      private String encoding;
      public void setEncoding(String encoding){
        this.encoding = encoding;
      public void doFilter(ServletRequest sRequest, .....){
       HttpServletRequest request = (HttpServletRequest) sRequest;
       HttpServletRequest response = (HttpServletResponse) sResponse;
       response.setContentType("text/html; charset="+this.encoding);
       filterChain.doFilter(request, response);
      It worked... And the "CharacterEncodingFilter" from Spring wasn't enough... It didn't set the content type...

      But thanks a lot!!