Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:38:40+00:00 2026-05-31T17:38:40+00:00

When I was still using PrimeFaces v2.2.1, I was able to type unicode input

  • 0

When I was still using PrimeFaces v2.2.1, I was able to type unicode input such as Chinese with a PrimeFaces input component such as <p:inputText> and <p:editor>, and retrieve the input in good shape in managed bean method.

However, after I upgraded to PrimeFaces v3.1.1, all those characters become Mojibake or question marks. Only Latin input comes fine, it are the Chinese, Arabic, Hebrew, Cyrillic, etc characters which become malformed.

How is this caused and how can I solve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:38:41+00:00Added an answer on May 31, 2026 at 5:38 pm

    Introduction

    Normally, JSF/Facelets will set the request parameter character encoding to UTF-8 by default already when the view is created/restored. But if any request parameter is been requested before the view is been created/restored, then it’s too late to set the proper character encoding. The request parameters will namely be parsed only once.

    PrimeFaces encoding fail

    That it failed in PrimeFaces 3.x after upgrading from 2.x is caused by the new isAjaxRequest() override in PrimeFaces’ PrimePartialViewContext which checks a request parameter:

    @Override
    public boolean isAjaxRequest() {
        return getWrapped().isAjaxRequest()
                || FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().containsKey("javax.faces.partial.ajax");
    }
    

    By default, the isAjaxRequest() (the one of Mojarra/MyFaces, as the above PrimeFaces code has obtained by getWrapped()) checks the request header as follows which does not affect the request parameter encoding as request parameters won’t be parsed when a request header is obtained:

        if (ajaxRequest == null) {
            ajaxRequest = "partial/ajax".equals(ctx.
                getExternalContext().getRequestHeaderMap().get("Faces-Request"));
        }
    

    However, the isAjaxRequest() may be called by any phase listener or system event listener or some application factory before the view is been created/restored. So, when you’re using PrimeFaces 3.x, then the request parameters will be parsed before the proper character encoding is been set and hence use the server’s default encoding which is usually ISO-8859-1. This will mess up everything.

    Solutions

    There are several ways to fix it:

    1. Use a servlet filter which sets ServletRequest#setCharacterEncoding() with UTF-8. Setting the response encoding by ServletResponse#setCharacterEncoding() is by the way unnecessary as it won’t be affected by this issue.

      @WebFilter("/*")
      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);
          }
      
          // ...
      }
      

      You only need to take into account that HttpServletRequest#setCharacterEncoding() only sets the encoding for POST request parameters, not for GET request parameters. For GET request parameters you’d still need to configure it at server level.

      If you happen to use JSF utility library OmniFaces, such a filter is already provided out the box, the CharacterEncodingFilter. Just install it as below in web.xml as first filter entry:

      <filter>
          <filter-name>characterEncodingFilter</filter-name>
          <filter-class>org.omnifaces.filter.CharacterEncodingFilter</filter-class>
      </filter>
      <filter-mapping>
          <filter-name>characterEncodingFilter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>
      

    2. Reconfigure the server to use UTF-8 instead of ISO-8859-1 as default encoding. In case of Glassfish, that would be a matter of adding the following entry to <glassfish-web-app> of the /WEB-INF/glassfish-web.xml file:

      <parameter-encoding default-charset="UTF-8" />
      

      Tomcat doesn’t support it. It has the URIEncoding attribute in <Context> entry, but this applies to GET requests only, not to POST requests.


    3. Report it as a bug to PrimeFaces. Is there really any legitimate reason to check the HTTP request being an ajax request by checking a request parameter instead of a request header like as you would do for standard JSF and for example jQuery? The PrimeFaces’ core.js JavaScript is doing that. It would be better if it has set it as a request header of XMLHttpRequest.


    Solutions which do NOT work

    Perhaps you’ll stumble upon below “solutions” somewhere on the Internet while investigating this problem. Those solutions do won’t ever work in this specific case. Explanation follows.

    • Setting XML prolog:

      <?xml version='1.0' encoding='UTF-8' ?>
      

      This only tells the XML parser to use UTF-8 to decode the XML source before building the XML tree around it. The XML parser actually being used by Facelts is SAX during JSF view build time. This part has completely nothing to do with HTTP request/response encoding.

    • Setting HTML meta tag:

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      

      The HTML meta tag is ignored when the page is served over HTTP via a http(s):// URI. It’s only been used when the page is by the client saved as a HTML file on local disk system and then reopened by a file:// URI in browser.

    • Setting HTML form accept charset attribute:

      <h:form accept-charset="UTF-8">
      

      Modern browsers ignore this. This has only effect in Microsoft Internet Explorer browser. Even then it is doing it wrongly. Never use it. All real webbrowsers will instead use the charset attribute specified in the Content-Type header of the response. Even MSIE will do it the right way as long as you do not specify the accept-charset attribute.

    • Setting JVM argument:

      -Dfile.encoding=UTF-8
      

      This is only used by the Oracle(!) JVM to read and parse the Java source files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the feeling I am still using asp type scripting techniques in the
I have clients who still using dot matrix for making copies of printed documents
All, As I am still using CakePHP 1.3 I am in need of using
Probably a dumb question, but is it still using Include files?
I just realized that my app, with over 300 users still using an Android
i still see people using ftp or telnet for work instead of sftp and
Ok, I'm still new to using C sockets, but I was wondering if there
I know I know, why am I using MP4 still?? It's because I have
I'm using ASP.Net MVC (still 1.0 for now) with Castle ActiveRecord and NHibernate.Linq. All
I still find myself hand coding Visual Studio projects more than using the variety

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.