JSF character encoding issues (unicode symbols)
britt.fitch Aug 19, 2010 11:23 AMThe 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
facelets 1.1.14
richfaces 3.3.3.final
tomcat 6
jdk1.6
I have tried a ton of things to resolve this including:
1.) creating a filter to set the character encoding to utf-8.
2.) overridding the view handler to force calculateCharacterEncoding to always return utf-8
3.) adding <meta http-equiv="content-type" content="text/html;charset=UTF-8" charset="UTF-8" /> to my page.
4.) setting different combinations of 'URIEncoding="UTF-8"' and 'useBodyEncodingForURI="true"' in tomcat's server.xml
5.) etc... like trying set encoding on an f:view, using f:verbatim, specifying escape attirbute on some output components.
all with no success.
There is a lot of great information on BalusC's site regarding this problem (http://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.html) but I have not been able to resolve it yet.
i have 2 test pages i am using.
if i put these symbols in a jsp (which does NOT go through the faces servlet) it renders fine and the page info shows that it is in utf-8.
{code}
Header 1 |
---|
<html> <head> <!-- <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> --> </head> <body> <br/>copy tag: © <br/>js/jsp unicode: © <br/>xml unicode: © <br/>u2460: \u2460 <br/>u0080: \u0080 <br/>arrow: » <p /> </body> </html> |
{code}
if i put these symbols in an xhtml page (which does go through the faces servlet) i get the black diamond symbols with a ? even though the page info says that it is in utf-8.
{code}
Header 1 |
---|
<!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" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:c="http://java.sun.com/jstl/core" xmlns:a4j="http://richfaces.org/a4j"> <head> <meta http-equiv="content-type" content="text/html;charset=UTF-8" charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> </head> <body> <br/>amp/copy tag: &copy; <br/>copy tag: © <br/>copy tag w/ pound: #© <br/>houtupt: <h:outputText value="©" escape="true"/> <br/>houtupt: <h:outputText value="©" escape="false"/> <br/>js/jsp unicode: © <br/>houtupt: <h:outputText value="©" escape="true"/> <br/>houtupt: <h:outputText value="©" escape="false"/> <br/>xml unicode: © <br/>houtupt: <h:outputText value="©" escape="true"/> <br/>houtupt: <h:outputText value="©" escape="false"/> <br/>u2460: \u2460 <br/>u0080: \u0080 <br/>arrow: » <br/>cdata: <![CDATA[©]]> <p /> </body> </html> |
{code}
on a side note, i have another application that is using myfaces 1.1, facelets 1.1.11, and richfaces 3.1.6 and the unicode symbols work fine.
i had another developer try to use my test xhtml page in his mojarra implementation and it works fine there using facelets 1.1.14 but NOT myfaces or richfaces.
i am convinced that somewhere between the view handler and the faces servlet the encoding is being set or reset but i havent been able to resolve it.
if anyone at all can point me in the right direction i would be eternally greatful.
thanks in advance.