JSF2 Form to DB special characters handling

I have the simplest possible JSF2 form inserting a table field in a MySQL db.

My facelet has <?xml version="1.0" encoding="UTF-8"?> at the top.

My input is a thing like <h:inputText value="#{testController.entity.test}" id="test" />

So I try to insert "provà" in my Jpa2/Hibernate entity. Then I persist it and, when I look for the saved value in my MySQL db....

I find "provÃ". It's the same old encoding problem I always solve by trying and trying....

Can you suggest me what to check first for fixing it?

I mean, I know there's a lack of info in this question, I just wanna see what do you ask me: in your questions I will find the answer! :)

Answers


My facelet has <?xml version="1.0" encoding="UTF-8"?> at the top.

This is irrelevant to the problem. This only tells the XML parser which charset to use when reading the XML file content before parsing it into a tree based hierarchy.

Your concrete problem can have 2 possible causes:

  1. The HTTP request character encoding is not set right. This is however not a normal situation as JSF/Facelets by default already uses UTF-8 throughout all layers. This problem can however occur whenever something else has accessed the HTTP request body before JSF/Facelets has set the proper character encoding. PrimeFaces 3.x is known to do that. See also Unicode input retrieved via PrimeFaces input components become corrupted. One of the ways to fix this is creating a filter which look like as in UTF-8 form submit in JSF is corrupting data.

  2. The JDBC connection character encoding is not set right. The MySQL JDBC driver uses the client platform default character encoding instead of the server table character encoding. Make sure that your MySQL JDBC URL look like as follows:

    jdbc:mysql://localhost:3306/db_name?useUnicode=yes&characterEncoding=UTF-8
    

Try putting h:form acceptcharset="UTF-8" in your xhtml(worked for me):


Need Your Help

Apache Rewrite Trailing Slash

apache .htaccess redirect

I am trying to use the following:

what shall i use VB.net or C# for desktop application

c# vb.net user-interface desktop

im coming from unix / server / c++ /java background with no GUI experience