Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF-8 in PrimeFaces 3.x

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?

like image 959
zorro6064 Avatar asked Jun 24 '12 12:06

zorro6064


1 Answers

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

like image 188
BalusC Avatar answered Sep 30 '22 18:09

BalusC