Results 1 to 3 of 3

Thread: UTF-8 in AbstractWizardFormController and Freemarker

  1. #1
    Join Date
    Feb 2008
    Posts
    26

    Default 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!

    Thanks,
    Yoann

  2. #2

    Default

    I always add accept-charset="utf-8" to my form tags:
    Code:
    <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:
    Code:
    <bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
    ...
    <property name="defaultEncoding" value="UTF-8" />
    </bean>
    And lastly, are you using Spring's CharacterEncodingFilter?

  3. #3
    Join Date
    Feb 2008
    Posts
    26

    Default

    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...

    Code:
    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);
     response.setCharacterEncoding(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!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •