6
votes

I have a very simple application,there is an inputtext in my index page and a button to go to page2.xhtml.

    <h:body>
        <h:form>
            <h:inputText value="#{mainBean.testValue}"/>
            <p:commandButton update="myoutput" value="ajax call" ajax="false"/>
            <p:separator />
            <h:commandButton action="#{mainBean.gotoPageTwo}" value="goto Page2"/>
            <br/>
            <h:outputText value="#{mainBean.testValue}" id="myoutput"/>
        </h:form>
    </h:body>
</html>

I tested this application with PrimeFaces 2.2.1 and there was no problem. but after submit each of the above button, my UTF-8 characters will destroy. I tested filter but it don't work. Is it a bug in PrimeFaces 3.x? Can any body solve this problem?

1
Have you tried to localise where the problem is? Does the appserver send UTF-8 to your browser, but the response headers say it's (e.g.) Latin1? Or does the appserver / framework convert your characters to to Latin1 before sending them to the browser?millimoose
I checked Content-Type with firebox and it was: text/html;charset=UTF-8. Notice that there is no problem with primefaces 2.2.1zorro6064

1 Answers

5
votes

The web.xml example of the answer you found at PrimeFaces forum is incomplete. The <filter-mapping> is missing. Without that, the filter won't even run at all. Add it accordingly

<filter-mapping>
    <filter-name>Character Encoding Filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

When you're already on Servlet 3.0 (Tomcat 7, Glassfish 3, etc), an alternative is to use just the @WebFilter annotation on the class. Don't forget to remove the filter entry from web.xml.

@WebFilter("/*")

For a background explanation of the cause of this character encoding problem during PrimeFaces 2.x-3.x upgrade, see also Unicode input retrieved via PrimeFaces input components become corrupted