3.0-SNAPSHOT Regression: character encoding warning

UI Components for JSF
Post Reply
User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

22 Feb 2011, 19:55

After updating to the latest 3.0-SNAPSHOT I've started to get character encoding warnings from GlassFish. I changed no code, just updated to latest version of PrimeFaces. The warning message appears in the GlassFish logs as:
WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /myproject, because request parameters have already been read, or ServletRequest.getReader() has already been called
I've found a few reports of this phenomenon from the past:

http://primefaces.prime.com.tr/forum/se ... ds=pwc4011

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

18 Mar 2011, 17:57

I've added a servlet filter that sets both the response and request character encoding to UTF-8 and that does remove the warning.

It seems since upgrading to latest PrimeFaces you must specify a character encoding via a servlet filter. Maybe PrimeFaces used to do this for you and now doesn't?

Seems like a big oversight that everyone who creates a Java web app (PrimeFaces or not) has to create the same 'ol servlet filter to set the character encoding. Maybe there is an option in GlassFish to just do the right thing? It seems like the default should be UTF-8 (instead of ISO8859-1), but more importantly it seems like the request and reponse encoding should always be in snyc by default. I suspect it is rare that someone would actually want to have one character encoding for their request and a different one for their response. I guess "configuration by exception" wasn't around when character encoding decisions for Java were made.

primeuser2412
Posts: 23
Joined: 18 Mar 2011, 03:49

19 Apr 2011, 15:46

Can I borrow your post and vent similar frustration as well? :D

Writing a Filter to provide UTF-8 character encoding is so old-schooled - it's like going back years! I mean we're in JSF 2 times now and still we have to write a custom filter to do UTF-8 encoding? Come on, people, it's not as if we've just invented the World Wide Web, you know!

Everything should be UTF-8-enabled by default: web servers, application servers, databases... whatever... About time we knock ISO-8859-1 off its pedestal and let's stop writing custom filter, shall we?! ;)

ymenager
Posts: 3
Joined: 11 Jun 2011, 23:21

13 Jun 2011, 20:56

In the case of glassfish you can set the default-charset attribute of the parameter-encoding element in the sun-web.xml ( or glassfish-web.xml in the case of 3.1) :-)

I also do vaguely remember there's also a way to set default encoding in tomcat.

monakhv
Posts: 42
Joined: 08 Feb 2010, 14:01

14 Jun 2011, 09:29

Hi!

As for me UTF8-filter does not solve warning message problem (but does solve encoding problem).
So here my solution for UTF-8 problem for Glassfish 3.1.

1 Remove your UTF-8 filter
2 put in your sun-web.xml

Code: Select all

<sun-web-app error-url="">
...

<locale-charset-info>
      <locale-charset-map locale="<whatever you need>" charset="utf-8"/>
      <parameter-encoding default-charset="utf-8"/>
  </locale-charset-info>
 
</sun-web-app>


User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

14 Jun 2011, 14:11

A few points:
  • In GlassFish 3.1 you should use glassfish-web.xml not sun-web.xml.
  • The locale-charset-info element is deprecated.
  • You would still need a filter to set the response encoding -- the parameter-encoding element only applies to the request encoding.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 42 guests