Wrong Character Set for JSF's h:inputText on first submit (only)

character encoding in java example
java charset utf-8 example
charset java
java default charset
java special characters encoding
charset java example
spring character encoding
spring boot character encoding

In the following form, we try to return a user's input to JSF's h:inputText or PrimeFaces' p:inputText. We experience strange behavior when non-Latin characters (Japanese, Hebrew, etc. ) are entered:

On first request we get unrecognized character set, but on the second request - we get a correct result.

Input/Output Examples (first run only):

  1. Japanese: input = 日 output = æ¥

  2. Hebrew: input = א output = ×


<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
            <h:outputLabel value="Name:"/>                        
            <h:inputText value="#{newTestController.registeredCustomerFirstName}"/>
            <h:commandButton value="Continue" action="#{newTestController.RegisteredNewCustomer(actionEvent)}"/>

Backing Bean:

@ManagedBean(name = "newTestController")
public class NewTestController {

    private String registeredCustomerFirstName;

    public String getRegisteredCustomerFirstName() {
        return registeredCustomerFirstName;

    public void setRegisteredCustomerFirstName(String registeredCustomerFirstName) {
        this.registeredCustomerFirstName = registeredCustomerFirstName;

    public void RegisteredNewCustomer(ActionEvent actionEvent) throws Exception {

As commented above - it is needed to define a default-charset for the application server.

For glassfish: add <parameter-encoding default-charset="UTF-8" /> to glassfish-web.xml.

For other application servers see BalusC's blog regarding this issue.

Lessons Learned: Solving character encoding issues in JSF, If no character encoding should be set, return * null . images and other resources as UTF-8 will probably generate an encoding error. It looks like somewhere internally in JSF the character set is changed to ISO. I've been through the sources, and I've found several pieces of code that support that theory. I've seen portions of code where the character set for the response is set to that of the request. Which in my case coming from a dutch system, will be ISO.

This is related to < http://java.net/jira/browse/GLASSFISH-18007 >. That fix was made to prevent a warning message when we unconditionally set the encoding to UTF-8, which would seem to be what we want, but in this case we felt it safer to not do it.

I've created a related issue in Mojarra, < http://java.net/jira/browse/JAVASERVERFACES-2217 >. Bottom line: setting the encoding explicitly in the app configuration is the right solution. The implementation is already doing the right thing.

JSF character encoding issues (unicode symbols)| JBoss.org , The basic problem i have is that i cannot get the copyright symbol or the chevron symbols to display in my pages. I am using: myfaces 2.0.0� Only when you're using a custom filter or a 3rd party component library which calls request.getParameter() or any other method which implicitly needs to parse the request body in order to extract the data, then there's chance that it's too late for JSF/Facelets to set the UTF-8 character encoding before the request body is been parsed for the

Specifying charset in the config file might be not enough. Try using p:commandButton instead of h:commandButton. The p:commandButton by default uses ajax, while the h:commandButton does non-ajax submit.

Charset (Java Platform SE 7 ), This class also defines static methods for testing whether a particular charset is Every instance of the Java virtual machine has a default charset, which may or Implementations of such charsets should override this method to return false. By default if you don’t change the separator character the id of the username field would be user-form:username but because we change the default character this results to user-form-username. This is much easier to use with css or javascript selectors.

Sun Java Article, Figure 2. Incorrect Character Encoding Information. The text is actually UTF-8 (a Unicode encoding) text. After placing this information in the HTML code as a� The platform independent way to do this is to use ServletRequest.setCharacterEncoding(java.lang.String) before processing the request parameters.. If you're using a framework that interprets the request for you, you can use a servlet filter instead:

Making Tomcat UTF-8-Ready, UTF-8 is the most common character encoding used in web applications. It supports all Encoding. The other part of our web application we need to configure is Java server pages. character-set-client-handshake = FALSE. JSF character encoding issues (unicode symbols) britt.fitch Aug 19, 2010 11:23 AM The basic problem i have is that i cannot get the copyright symbol or the chevron symbols to display in my pages.

Guide to Character Encoding, Explore character encoding in Java and learn about common pitfalls. What could have gone wrong? We'll try to understand and correct this� Introduction. In this tutorial you will learn how to set up a JSF (Jakarta Faces) 2.3 development environment with the Eclipse IDE, the Maven dependency management system, the WildFly application server, and the H2 database from scratch.

  • h:inputText is from standard JSF. Don't you mean p:inputText? As to the problem, how and where exactly did you confirm that the characters are mojibake? While printing to logs and reading it? Or when checking the redisplayed form after submit?
  • Sorry. This happens both on p:inputText and h:input, so it's probably relevant to JSF, not primefaces. As to the problem: It is visible upon re-displaying, logging and a breakpoint set on getRegisteredCustomerFirstName().
  • I have a solution without an explanation. For glassfish add:<parameter-encoding default-charset="UTF-8" /> to glassfish-web.xml. Still - why is it failing on the first time only?
  • @Daniel What is the solution for tomcat, any idea?
  • @Koray Tugay Maybe. Have you tried:balusc.blogspot.co.il/2009/05/… ? Clause 3 includes some notes about tomcat.
  • Hello, I am using Tomcat however I have the exact same problem.
  • Did setting the configuration in the app as explained in issue 2217 not resolve the problem there?
  • Please see: stackoverflow.com/questions/16544262/… @edburns thanks.