In one of the projects I have non-English content (Finnish) available on form data. We are using JSF 2.0 with PrimeFaces. I have trouble when submitting the data to the server. The data is getting corrupted when I submit the form. Only the Finnish characters are getting corrupt in that.
Has anyone faced this issue already and found a solution?
This is a known problem since PrimeFaces 3.0. It's caused by a change in how it checks if the current HTTP request is an ajax request. It's been identified by a request parameter instead of a request header. When a request parameter is retrieved for the first time before the JSF view is restored, then all request parameters will be parsed using server's default character encoding which is often ISO-8859-1 instead of JSF's own default character encoding UTF-8. For an in depth explanation see Unicode input retrieved via PrimeFaces input components become corrupted.
One of the solutions is to create a filter which does a request.setCharacterEncoding("UTF-8")
.
@WebFilter("*.xhtml")
public class CharacterEncodingFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With