13 Replies Latest reply on Feb 17, 2009 4:01 PM by Roland Schöler

    Encodingproblem with rich:comboBox

    Roland Schöler Newbie

      Hi folks, according to my surrounding, from where I am, I use the locale de.
      Now I've faced a problem with so called "Umlaute", e.g. LATIN SMALL LETTER A WITH DIAERESIS = ä in HTML 4.0, if using in combination with rich:comboBox.

      I've no problems using this characters in input, output or other elements only with using them in rich:comboBox.

      Using the following page-source - the word "Sichtqualität" (similiar to view-quality or so) is shown as "Sichtqualität".
      Spelled after the String Sichtqualit => ambersand, number-sign, 2,2,8,semicolon (only to be sure 8-})

      <rich:comboBox id="idList" value="#{mappingHandler.selectedIdentifier}" suggestionValues="#{mappingHandler.allIdentifiers}"
       directInputSuggestions="true" defaultLabel="Enter some value">
       <a4j:support event="onselect" reRender="list_of_mappings" />
       </rich:comboBox>


      I've tried a lot of things:
      - changing META content-type
      - do decoding by my own
      - playing with browser-Encode-setting
      - trying different parsing-method (which I've found some descriptions in other post regarding encoding-problems - mean CDK-parsing values)

      Additional short description: Values are stored in database; Logging output show me correct spelling after lookup in database

      My Environment:
      - jdk1.6.0_11
      - RF 3.3.0 GA
      - MyFace 1.2.5
      - Apache Tomcat/6.0.16 (Standalone)

      Currently I've no more idea where to go, and the book "Practical RichFaces" from Max Katz hasn't reached me until now.....8-}

      regards
      roland

        • 1. Re: Encodingproblem with rich:comboBox
          Florian Marwede Expert

          Hi rschoeler!

          Look at these three issues and how they are related:

          - https://jira.jboss.org/jira/browse/RF-4985
          - https://jira.jboss.org/jira/browse/RF-5639
          - https://jira.jboss.org/jira/browse/RF-5964

          And finally the link to a myfaces problem:

          https://issues.apache.org/jira/browse/MYFACES-2126

          It would be helpful if you could test, if your bug is already there without using myfaces.

          • 2. Re: Encodingproblem with rich:comboBox
            Roland Schöler Newbie

            Hi fmarwede, thank you for pointing me to the issues!

            Naturally I've tried to switch from MyFace to Sun RI and for this problem - Encoding with rich:comboBox - I can verify that using Sun RI (mojarra-1.2_12-binary) solve this problem.......but other problems - no AJAX-Functionality works anymore - occured. 8-{

            I will do a little research and try some things, because it's the first time I use Sun RI. Maybe I need some setting or so - although the pdf-documentation sounds, that no explicit setting is necessary.

            wfg
            roland

            • 3. Re: Encodingproblem with rich:comboBox
              Florian Marwede Expert

              Hi Roland,
              in my experience you need (when you switch from MyFaces to Sun) (a) another combination of supporting jars (i mean this apache common stuff and so on) and (b) another configuration of the web.xml.

              Are you sure, that you considered both aspects sufficiently?

              • 4. Re: Encodingproblem with rich:comboBox
                Nick Belaevski Master

                 

                "rschoeler" wrote:
                Hi fmarwede, thank you for pointing me to the issues!

                Naturally I've tried to switch from MyFace to Sun RI and for this problem - Encoding with rich:comboBox - I can verify that using Sun RI (mojarra-1.2_12-binary) solve this problem.......but other problems - no AJAX-Functionality works anymore - occured. 8-{

                I will do a little research and try some things, because it's the first time I use Sun RI. Maybe I need some setting or so - although the pdf-documentation sounds, that no explicit setting is necessary.

                wfg
                roland

                Hi Roland,

                I've just tried to run richfaces-demo using 1.2_12 JSF. Quick check ok. Can you please clarify what components don't work and what issue do you experience?

                • 5. Re: Encodingproblem with rich:comboBox
                  Roland Schöler Newbie

                  Hi farmwede&nbelaevski, thanks for your help. I've found the soure of my AJAX-Problem....forgot to remove parameter "org.ajax4jsf.xmlparser.ORDER" from my web.xml....was an artifact from some earlier tries.
                  After removing this param - everything works fine with Sun RI.
                  Switching between this two implementations is really easy....8-}

                  Now I've found a solution for this problem which works for both Implementations. Cost me some time - but it works now!
                  Maybe this solution will also works for other problems regarding encoding stuff - can someone forward this information to RF docu team &

                  1. Using Sun RI (mojarra-1.2_12-binary)
                  => nothing to do, because Umlaute are presented like they are!

                  2. Using Apache MyFace (v. 1.2.5)
                  => using an own filter, which ensures correct used encoding (see code above)
                  => don't forget Encoding in HEADER-Tag
                  => also update web.xml with filter-class

                  Source for my Solution according Apache MyFace/Tomcat:
                  http://wiki.apache.org/tomcat/Tomcat/UTF-8

                  My own filter (very similar to the one from the URL above):

                  import java.io.IOException;
                  
                  import javax.servlet.Filter;
                  import javax.servlet.FilterChain;
                  import javax.servlet.FilterConfig;
                  import javax.servlet.ServletException;
                  import javax.servlet.ServletRequest;
                  import javax.servlet.ServletResponse;
                  
                  public class CharsetFilter implements Filter {
                  
                   private String encoding;
                  
                   public void init(FilterConfig config) throws ServletException {
                   // TODO Auto-generated method stub
                   encoding = config.getInitParameter("encoding");
                  
                   if (encoding == null)
                   encoding = "UTF-8";
                   }
                  
                   public void doFilter(ServletRequest request, ServletResponse response,
                   FilterChain next) throws IOException, ServletException {
                   // TODO Auto-generated method stub
                   request.setCharacterEncoding(encoding);
                   response.setCharacterEncoding(encoding);
                  
                   next.doFilter(request, response);
                   }
                  
                   public void destroy() {}
                  }



                  wfg
                  roland

                  • 6. Re: Encodingproblem with rich:comboBox
                    Nick Belaevski Master

                    Hello,

                    Why not set encoding at page level? It should work without filter.

                    • 7. Re: Encodingproblem with rich:comboBox
                      Roland Schöler Newbie

                      Hello, naturally encoding is set at page level with META-Tag and contentType etc., but the problem with rich:comboBox isn't affected by this setting.
                      That was the problem. Everything else works fine with encoding on this page - except the rich:comboBox. Problem is reproduceable.

                      No problem with rich:comboBox if using Sun RI.
                      But problem exists, if using current release of Apache MyFaces - one solution for this, which works successfully: Filter, as described in posting

                      I don't know, why the page encoding doesn't work correctly - I only know that this is the case.

                      regards
                      roland

                      • 8. Re: Encodingproblem with rich:comboBox
                        Nick Belaevski Master

                        Do you use Facelets or JSP?

                        • 9. Re: Encodingproblem with rich:comboBox
                          Roland Schöler Newbie

                          Hi, only JSP - facelets will be done in a later stage, because I wasn't able to introduce them correctly in the short time I've had.



                          • 10. Re: Encodingproblem with rich:comboBox
                            Nick Belaevski Master

                            Try setting encoding using page directive:

                            <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
                            


                            • 11. Re: Encodingproblem with rich:comboBox
                              Roland Schöler Newbie

                              Hi Nick, thanks for your answer, but I was to fast and wrong with my answer.....this is my first project with JSF and it's some kind of evolutionary prototyp (although for professional work) - therefore it could contains a lot of mixing technologies/programming style etc......8-}

                              This is the start of my HTML-page - but every page looks very similar to this.

                              <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
                              <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
                              <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
                              <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
                              <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
                              
                              <f:view locale="#{facesContext.externalContext.request.locale}">
                              <f:loadBundle basename="messages" var="msgs"/>
                              <!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">
                              
                              <head>
                              <link type="text/css" href="./css/workplace.css" rel="stylesheet" media="screen">
                              <title><h:outputText value="#{msgs.article_title}"/></title>
                              <link rel="shortcut icon" href="./images/favicon.ico" type="image/x-icon">
                              <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
                              </head>
                              
                              <body>....
                              


                              • 12. Re: Encodingproblem with rich:comboBox
                                Nick Belaevski Master

                                Ok, here is the snippet for plain JSP pages:

                                <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>


                                For Facelets:
                                <?xml version="1.0" encoding="UTF-8" ?>


                                The reason for all this stuff is that response writer doesn't handle META tags, but uses request.getCharacterEncoding() to calculate encoding.

                                • 13. Re: Encodingproblem with rich:comboBox
                                  Roland Schöler Newbie

                                  Hi Nikolay, I've tried your snippet for plain JSP pages, cleaned the cache, removed my Charset-filter etc. - thanks for your explanation for the reason.

                                  Problem already there - it's a little bit enlighted, but still existing....8-{

                                  Following behaviour:
                                  1. Open page first time:
                                  => rich:comboBox doesn't show the correct spelling - if special characters are inside of the suggestionlist
                                  => rest of the page has correct spelling
                                  2. Select one item of the rich:comboBox
                                  => if the selected item is one of the misspelled one - the display is also mispelled, but the new constructed suggestionlist is correct spelled
                                  => if the selected item is not misspelled - the displayed selection is correct spelled, and the new constructed suggestionlist too
                                  => once the suggestionlist is correct displayed - the bug never appears, if you don't leave the page....
                                  3. Move away and come back
                                  => same behaviour as in point 1

                                  With help of this page http://www.utf8-chartable.de/unicode-utf8-table.pl?unicodeinhtml=dec&htmlent=1 I found out that the representation in the rich:comboBox is numerical HTML encoding of the Unicode character with decimal

                                  Now I know, that I must use my workaround with the charset-Filter until a new release of Apache MyFaces (or RichFace?) solve this problem......because I don't know, who is really responsible for this bug...;-}

                                  regards
                                  roland