When trying to enter my name into a JSF web form to test some underlying JPA code, the character ö broke into unreadable gibberish in both the view and the database, but when I entered another String with more Umlauts, it was displayed and saved correctly. The encoding error on the first request of a session (and only the first request) was reproducible and a look into the log revealed that encoding error happened before the Umlaut was passed to the setter inside the underlying bean. The page with the form (and all other pages in the project) was set correctly to UTF-8, so there was no apparent reason for the encoding error. A quick web search however led to this bug report for the Mojarra Project.
Since the bug was reported as fixed, a small test was necessary to ascertain the Mojarra library as the culprit, which was done by simply replacing Mojarra in the project with MyFaces. The character encoding error did not occur using MyFaces, so different Mojarra Versions from 2.1.4 to 2.2.4 were tested, all producing the same encoding error. So either the bug has not been fixed after all or this is a separate but most likely related issue. As mentioned here and in the bug report, there are two workarounds, both of them hardly satisfying:
- Change the JSF implementation from Mojarra to something else or
- Define the charset in your pages not as UTF-8, but as the default charset ISO-8859-1.
Both solutions can have major implications and are hardly appropriate for such a rather minor problem.