3 Replies Latest reply on Sep 7, 2010 10:56 AM by britt.fitch

    JSF character encoding issues (unicode symbols)

    britt.fitch

      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

      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: &copy;
              <br/>js/jsp unicode: &#169;
              <br/>xml unicode: &#xA9;
              <br/>u2460: \u2460
              <br/>u0080: \u0080
              <br/>arrow: &#187;
              <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: &amp;copy;
              <br/>copy tag: &copy;
              <br/>copy tag w/ pound: #&copy;
              <br/>houtupt: <h:outputText value="&copy;" escape="true"/>
              <br/>houtupt: <h:outputText value="&copy;" escape="false"/>
              <br/>js/jsp unicode: &#169;
              <br/>houtupt: <h:outputText value="&#169;" escape="true"/>
              <br/>houtupt: <h:outputText value="&#169;" escape="false"/>
              <br/>xml unicode: &#xA9;
              <br/>houtupt: <h:outputText value="&#xA9;" escape="true"/>
              <br/>houtupt: <h:outputText value="&#xA9;" escape="false"/>
              <br/>u2460: \u2460
              <br/>u0080: \u0080
              <br/>arrow: &#187;
              <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.

        • 1. Re: JSF character encoding issues (unicode symbols)
          britt.fitch

          UPDATE:

           

          by doing this as mentioned in BalusC's blog post i can get the symbols to render locally but not on the server.

           

          http://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.html#OkSoIHaveAnUnicodeProblemWhatNow

           

          see image below text "Important note: the Workspace encoding"

          • 2. Re: JSF character encoding issues (unicode symbols)
            britt.fitch

            UPDATE:

             

            If i set the workspace encoding in eclipse to UTF-8, then it rendereds unicode symbols fine.
            if i take the same war and deploy it on tomcat as a stand alone app outside of eclipse, then i get black diamonds with "?" instead of the symbols.

             

            i dont know how to get the encoded behavior i see in eclipse to happen outside of eclipse.
            any suggestions?

            • 3. Re: JSF character encoding issues (unicode symbols)
              britt.fitch

              UPDATE:

               

              I was unable to get the page itself to consume the various options for unicode characters like the copyright symbol.
              Ultimately the content I am trying to display is coming from a web service.
              I resolved this issue by calling the web service from my backing bean instead of using ui:include on the webservice call directly in the page.

               

              for example:

               

              {code}
              public String getFooter() throws Exception
                  {
                      HttpClient httpclient = new HttpClient();
                      GetMethod get = new GetMethod(url);
                      httpclient.executeMethod(get);
                      String response = get.getResponseBodyAsString();
                      return response;
                  }
              {code}

               

              I'd still love to have a solution to the page usage of the unicode characters, but for the time being this solves my problem.

              1 of 1 people found this helpful