11 Replies Latest reply on Sep 4, 2006 2:31 AM by minamoto

    unicode escaping problem

      Hi all.
      May be this question is JSF specific but I can't find solution for a five days.
      I'm using SEAM + Facelets + EJB3.
      When I post some data in Russian on <h:inputText>, I see codes of those charactrers when form redisplays instead of characters. On sun's forums I found that characters that are "dangerous" in HTML are escaped. But how can I get real characters from form.

      my code
      <h:inputText id="searchString" value="#{productOrdering.searchString}"/>

      Please help me, this is very important for me.

      Thanks
      --Andrew

        • 1. Re: unicode escaping problem

          Hadn't anyone had such a problem? Are here any people not from english-speaking country?

          • 2. Re: unicode escaping problem
            matthew.edwards

            See if you can ask the guy who puts up this website:

            http://jsf.iatp.org.ua/ru/index.html

            • 3. Re: unicode escaping problem
              lcoetzee

              We have 11 to support. Painful ;-)

              I have conducted a few experiments to try and solve it. I have seen that using Linux based browsers with Unicode (Mozilla, Firefox) seems to work OK. Using IE on Windows I am able to enter the Unicode, but the re-display in the inputtext shows the hex values.

              Did you try your application through different browsers? Would be interesting to know if you have the same behavior.

              Is your persistence store configured to save Unicode ? (I created my postgresql instance with "createdb -E UNICODE instancename")

              Regards
              Louis

              • 4. Re: unicode escaping problem

                Thanks for your reply Louis.
                I tested on FreeBSD and on Windows
                on FreeBSD:Firefox I get hex values
                on FreeBSD:Opera I get hex values
                but on FreeBSD we have russian encoding KOI8-R
                on Win:Firefox I get hex values
                on Win:Opera I get hex values
                and
                on Win:IE I get charecters on "some" encoding, not UTF-8, not cp1251 and not ISO8859-1
                :-(
                Yes my databese created with UTF-8 :-(

                So how can we solve this problem?

                again thanks for your reply
                --Andrew

                • 5. Re: unicode escaping problem

                  Page rendered with encoding ISO8859-1 on Firefox
                  and with encoding UTF-8 on IE

                  On facelets issue trucking system I found that page must be encoded with UTF-8 by default.

                  So IE show page in correct encoding, and firefox - not

                  • 6. Re: unicode escaping problem

                    But problem is still there:

                    if page rendered in UTF-8 I get charecters on "some" encoding, not UTF-8, not cp1251 and not ISO8859-1

                    if page rendered in ISO8859-1 I get hex values of input characters

                    • 7. Re: unicode escaping problem
                      deniss.parhomenko

                      try to register this filter,

                      but it? a hack for Oracle ADF, because some time Oracle ADF components reset utf encoding to ISO

                      public class UTF8Filter implements Filter {
                      
                       public UTF8Filter() {
                       super();
                       }
                      
                       public void init(FilterConfig arg0) throws ServletException {
                       // TODO Auto-generated method stub
                      
                       }
                      
                       public void doFilter(ServletRequest request, ServletResponse response,
                       FilterChain chain) throws IOException, ServletException {
                       HttpServletResponse r2 = (HttpServletResponse) response;
                       r2.setContentType("text/html; charset=utf-8");
                       response.setCharacterEncoding("utf-8");
                      
                       chain.doFilter(new ServletRequestUTF8((HttpServletRequest) request),
                       new MyResponseWrapper((HttpServletResponse) response));
                      
                       }
                      
                       public void destroy() {
                       // TODO Auto-generated method stub
                      
                       }
                      
                      }
                      
                      class MyResponseWrapper extends HttpServletResponseWrapper{
                      
                       @Override
                       public void setHeader(String arg0, String arg1) {
                       // TODO Auto-generated method stub
                       super.setHeader(arg0, arg1);
                       }
                      
                       @Override
                       public void setContentType(String arg0) {
                       // TODO Auto-generated method stub
                       super.setContentType("text/html; charset=utf-8");
                       }
                      
                       @Override
                       public void setResponse(ServletResponse arg0) {
                       // TODO Auto-generated method stub
                       super.setResponse(arg0);
                       }
                      
                       @Override
                       public String getCharacterEncoding() {
                       // TODO Auto-generated method stub
                       return "utf-8";
                       }
                      
                       @Override
                       public void setCharacterEncoding(String arg0) {
                       // TODO Auto-generated method stub
                       //super.setCharacterEncoding(arg0);
                       }
                      
                       public MyResponseWrapper(HttpServletResponse arg0) {
                       super(arg0);
                       // TODO Auto-generated constructor stub
                       }
                      
                      
                      }
                      
                      class ServletRequestUTF8 extends HttpServletRequestWrapper {
                      
                       /**
                       * @param arg0
                       */
                       public ServletRequestUTF8(HttpServletRequest arg0) {
                       super(arg0);
                       // TODO Auto-generated constructor stub
                       }
                      
                       public String getParameter(String arg0) {
                       return convertUTF8(super.getParameter(arg0));
                       }
                      
                       /**
                       * @param parameter
                       * @return
                       */
                       private String convertUTF8(String value) {
                       if (value == null) {
                       return value;
                       }
                       try {
                       return new String(value.getBytes("ISO-8859-1"), "UTF-8");
                       } catch (Throwable e) {
                       e.printStackTrace();
                       return value;
                       }
                       }
                      
                       public String[] getParameterValues(String arg0) {
                       String[] values = super.getParameterValues(arg0);
                       if (values == null){
                       return null;
                       }
                       for (int i = 0; i < values.length; i++) {
                       values = convertUTF8(values);
                      
                       }
                       return values;
                       }
                      }


                      • 8. Re: unicode escaping problem

                        Wow It's finaly working now!!!!!!!

                        Thanks Deniss!! :-)

                        In MyFaces filter working too.

                        Thanks everyone

                        --Andrew

                        • 9. Re: unicode escaping problem
                          lcoetzee

                          Hi

                          I havent tried the filter solution above. The following
                          https://facelets.dev.java.net/servlets/ReadMsg?list=users&msgNo=1403
                          has helped me! In short it uses a JSF Phase listerner.

                          Regards

                          Louis(now in multiple languages ;-)



                          • 10. Re: unicode escaping problem
                            nhpvti

                             

                            "lcoetzee" wrote:
                            Hi

                            I havent tried the filter solution above. The following
                            https://facelets.dev.java.net/servlets/ReadMsg?list=users&msgNo=1403
                            has helped me! In short it uses a JSF Phase listerner.

                            Regards

                            Louis(now in multiple languages ;-)





                            nice eclipse resource bundle editor makes your happiness complete
                            http://sourceforge.net/projects/eclipse-rbe/


                            • 11. Re: unicode escaping problem
                              minamoto

                              Without the JSF Phase listeners, I can input and show japanese characters correctly on utf-8 pages after installing facelets-1.1.11 for the seam package.
                              I recomend the newer versions of facelets.

                              Miki