I can normally write czech string to the form:
But after validation (a
I had exactly the same problem with validation form and I solved it with Sergey's answer.
BUT your filter needs to be in first position in your web.xml. Moving my filter from 3rd to first position solved my problem.
Hope it helps.
(Primefaces 3.2, JSF 2.1.2 with Jboss 7.1)
Given the symptoms, UTF-8 data is been redisplayed using ISO-8859-x encoding. The č
(LATIN SMALL LETTER C WITH CARON (U+010D)) exist in UTF-8 of bytes 0xC4
and 0x8D
. According to the ISO-8859-1 codepage layout those bytes represent the characters Ä
and [nothing] respectively, which is exactly what you're seeing.
This particular problem can have many causes. As Facelets by itself already uses UTF-8 by default to process HTTP POST request parameters and to write the HTTP response, there should/can be nothing which you need to fix/change in the Java/JSF side.
However, when you're manually grabbing a request parameter before JSF creates/restores the view (e.g. in a custom filter), then it may be too late for Facelets to set the right request character encoding. You'd need to add the following line to the custom filter before continuing the chain, or in a new filter which is mapped before the filter causing the trouble:
request.setCharacterEncoding("UTF-8");
Also, when you've explicitly/implicitly changed the Facelets' default character encoding by for example <?xml version="1.0" charset="ISO-8859-1"?>
or <f:view encoding="ISO-8859-1">
, then Facelets will use ISO-8859-1 instead. You'd need to replace it by UTF-8
or remove them altogether.
If that's not it, then only the database side is the major suspect. In that side I can see two possible causes:
How exactly to solve it depends on the DB server used. Usually you need to specify the charset during CREATE
of the DB table, but you can usually also alter it using ALTER
. As to the JDBC driver, this is usually to be solved by explicitly specifying the charset as connection URL parameter. For example, in case of MySQL:
jdbc:mysql://localhost:3306/db_name?useUnicode=yes&characterEncoding=UTF-8
Try this solution: http://ibnaziz.wordpress.com/2008/06/10/spring-utf-8-conversion-using-characterencodingfilter/ In my cases it helps (with russian)
In web.xml add Spring's character encoding filter:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>