13 Replies Latest reply on Aug 8, 2010 6:27 PM by maricool

    How to use UTF-8 characters like german umlauts or others in view pages

      Hi, this is one of the seam-gen generated views, which I have to make german-special-chars-ready (Umlaute).


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:s="http://jboss.com/products/seam/taglib"
                      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"
                      template="layout/template.xhtml">
      <ui:define name="body">
        <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
          <rich:panel>
              <f:facet name="header">Holiday</f:facet>
              <s:decorate id="day" template="layout/display.xhtml">
                  <ui:define name="label">day</ui:define>
                  <h:outputText value="#{holidayHome.instance.day}">
                      <s:convertDateTime type="date" dateStyle="short"/>
                  </h:outputText>
              </s:decorate>
              <s:decorate id="description" template="layout/display.xhtml">
                  <ui:define name="label">description</ui:define>
                  #{holidayHome.instance.description}
              </s:decorate>
              <div style="clear:both"/>
          </rich:panel>
          <div class="actionButtons">      
              <s:button view="/HolidayEdit.xhtml" id="edit" value="Edit"/>
              <s:button view="/#{empty holidayFrom ? 'HolidayList' : holidayFrom}.xhtml" id="done" value="Done"/>
          </div>
      </ui:define>
      </ui:composition>



      I tried several stuff, all leading to errorpages, so maybe someone can tell me, what has to be done. Maybe it will help others to avoid some frustration too.


      I want to use the special chars in the views directly (e.g. change the header, add extra texts), I want to use them as captions of buttons or generally as values of xml-params and I have them inside the database tables or generally inside the getter-methods of my entities.


      I assume, I have to escape the chars somehow and import them in the document-start, but don't get it right.


      If someone could edit the above example or point to a working view page example, I would be very happy.

        • 1. Re: How to use UTF-8 characters like german umlauts or others in view pages
          kariem

          Peter,


          It should not be a problem to populate your view from the DB. I think the DB and the driver should support the character set, but I really never had any issues with that, so I cannot tell.


          For the static information in your page, you could use message bundles. If you use the default encoding, it should be possible to to write umlauts into the properties file. If you want to be on the safe side, use unicode escaped characters for the properties files.


          If you save the xhtml file as UTF-8, and your editor knows how to write UTF-8, there should not be a problem to write any characters you like.


          Could you provide the error messages you have encountered?

          • 2. Re: How to use UTF-8 characters like german umlauts or others in view pages
            baz

            I would just wrap


            
            #{holidayHome.instance.description}
            
            
            


            in an h:outputText

            • 3. Re: How to use UTF-8 characters like german umlauts or others in view pages
              baz

              I forget to say that i use this stuff in a german adresstable application. I have not done any special, besides the outputText, to get it working.
              Ciao,
              Carsten

              • 4. Re: How to use UTF-8 characters like german umlauts or others in view pages
                msystems

                I have a multi-language web-application using Seam and I have no problems. But you need to ensure your application and database handles UTF-8 correctly.


                In the components.xml file, add:


                <web:character-encoding-filter encoding="UTF-8" override-client="true" url-pattern="*.xhtml"/>
                



                What database are you using?


                PostgreSQL have problems with sorting if you want to use multiple languages. But if you are using PostgreSQL you need to initialize the database to use UTF-8:


                /usr/local/pgsql/bin/initdb -E UTF8 -D /usr/local/pgsql/data --locale=da_DK



                MySQL supports multiple languages and I will recommend MySQL if you need to support multiple languages.


                For UTF-8 and multi-language support add following lines to the my.cnf file:


                #Set the default character set.
                default-character-set=utf8
                #Set the default collation.
                default-collation=utf8_unicode_ci
                



                And remember to use COLLATE when you e.g. wants to sort:


                COLLATE


                BTW: HQL and EJB-QL don't support the keyword 'COLLATE' !


                Quote, Kariem Hussein:




                If you save the xhtml file as UTF-8, and your editor knows how to write UTF-8, there should not be a problem to write any characters you like.

                Correctly. I'm using IntelliJ IDEA and all my files are saved in UTF-8.

                • 5. Re: How to use UTF-8 characters like german umlauts or others in view pages
                  nickarls

                  Kenneth Christensen wrote on Feb 22, 2008 08:11 AM:


                  I have a multi-language web-application using Seam and I have no problems. But you need to ensure your application and database handles UTF-8 correctly.


                  Does your web filter config also enable you to use command links and EL to method names with special characters? I recall trying but having problems with the URL encodings etc? Could also have been an AS config thing, didn't spend so much time on that.

                  • 6. Re: How to use UTF-8 characters like german umlauts or others in view pages
                    msystems

                    Nicklas Karlsson wrote on Feb 22, 2008 08:57 AM:



                    Kenneth Christensen wrote on Feb 22, 2008 08:11 AM:


                    I have a multi-language web-application using Seam and I have no problems. But you need to ensure your application and database handles UTF-8 correctly.


                    Does your web filter config also enable you to use command links and EL to method names with special characters? I recall trying but having problems with the URL encodings etc? Could also have been an AS config thing, didn't spend so much time on that.


                    I can't help you because I'm only using english characters in my code :-)

                    • 7. Re: How to use UTF-8 characters like german umlauts or others in view pages

                      Oh, I had two or three different ones, but this forum killed my developer machine when I wanted to ask for help and so all my notes on this issue were gone. :/
                      Fortunately I had my project backed up in a svn-repository so it only took me two days to set up the system again.


                      I tried some of the stuff again and I think the most common one is:


                      Error Parsing /HolidayEdit.xhtml: Error Traced[line: 20] Invalid byte 2 of 3-byte UTF-8 sequence



                      I solved it now by opening the files with a better editor, changing the format to utf-8, thanks a lot.


                      As database I am forced to use MySQl, but without access to the conffiles, so I tried it by changing the database and table encodings.


                      create database cdb character set utf8 collate utf8_bin;
                      create table holiday ( id bigint not null auto_increment, day date, description varchar(40),
                        constraint unique (day), primary key (id)) character set utf8 collate utf8_bin;



                      This didn't help, the web pages looked much better, but the Strings I put into database were still without the expected chars.


                      So I tried to create a new item and clicked save. It was shown correctly in the forms, but the string, which had been saved to the database doesn't look very nice. This wouldn't be that bad, but I have many insert-statements in a file and I don't know how to read them in to fit this messy format.


                      I also tried to change the file components.xml by adding the above string as mentioned, but I get a deploy-exception:


                      <web:character-encoding-filter encoding="UTF-8" override-client="true" url-pattern="*.xhtml"/>



                      ERROR [StandardContext] Error listenerStart
                      ERROR [StandardContext] Context [/gdc] startup failed due to previous errors
                      WARN  [ServiceController] Problem starting service jboss.web.deployment:war=gdc.war,id=-806708607
                      org.jboss.deployment.DeploymentException: URL file:/F:/qi/installs/jboss/server/default/tmp/deploy/tmp58903gdc.ear-contents/gdc.war/ deployment failed
                             at org.jboss.web.tomcat.service.TomcatDeployer.performDeployInternal(TomcatDeployer.java:379)
                             at org.jboss.web.tomcat.service.TomcatDeployer.performDeploy(TomcatDeployer.java:104) ...



                      Removing the line again solves the deploy-problem but I'm still there with my messy sql tables.




                      • So, where do I have to put the character-encoding-filter to get it to work, are the parameters correct???




                      Thanks for all informations till now and all further posts.

                      • 8. Re: How to use UTF-8 characters like german umlauts or others in view pages
                        msystems

                        So, where do I have to put the character-encoding-filter to get it to work, are the parameters correct??

                        In the components.xml !


                        Remember to declare the web xml ns in the components:


                        <components xmlns:web="http://jboss.com/products/seam/web"
                                                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd">

                        • 9. Re: How to use UTF-8 characters like german umlauts or others in view pages

                          Okay, forgot the namespace-declaration, thanks for reminding!


                          Now I only have the problem of wrong inside-database-representation, but maybe this is a MySQL-problem.


                          When I create an entry in the seam forms and view it in the seam forms all is okay. But the strings in the database differ when I create them with seam or by hand. Any Hints?


                          Below is the result of typing ö in a field, first one by hand in the mysql-console, second one using the seam-form. Which one is right now??


                          mysql> select ascii(last_name) from person where id <4;
                          +------------------+
                          | ascii(last_name) |
                          +------------------+
                          |              226 |
                          |              195 |
                          +------------------+


                          • 10. Re: How to use UTF-8 characters like german umlauts or others in view pages
                            msystems

                            Please read http://dev.mysql.com/doc/refman/5.0/en/internationalization-localization.html


                            To see the values of the character set and collation system variables that apply to your connection, use these statements:


                            SHOW VARIABLES LIKE 'character_set%';
                            SHOW VARIABLES LIKE 'collation%';



                            Here is a dump from my MySQL:


                            SHOW VARIABLES LIKE 'character_set%:
                            
                            character_set_client             utf8
                            character_set_connection     utf8
                            character_set_database             utf8
                            character_set_filesystem     binary
                            character_set_results     
                            character_set_server             utf8
                            character_set_system             utf8
                            character_sets_dir             /usr/local/mysql-5.0.45-osx10.4-i686/share/mysql/charsets/
                            



                            and


                            SHOW VARIABLES LIKE 'collation%':
                            
                            collation_connection     utf8_general_ci
                            collation_database     utf8_unicode_ci
                            collation_server     utf8_unicode_ci
                            



                            As mentioned earlier I have no problems with the setup (Seam and DB) I explained in some of my previous comment.

                            • 11. Re: How to use UTF-8 characters like german umlauts or others in view pages

                              I have the same settings, but it still didn't work. Now I found a way:


                              Formerly I used the mysql-console started in a dos-box and pasted the insert-statements in from a file opened in an editor. This lead  to error messages like:


                              mysql> insert into person (first_name) values ('Jörg');
                              ERROR 1366 (HY000): Incorrect string value: '\x94rg' for column 'first_name' at row 1



                              So, now I tried it via the MySQL GUI tools and it worked.
                              It seems to be a mysql-console-problem in windows.


                              Another way, which can be batched, is to pipe the data into the mysql-console:


                              type 05_insert_statements.sql | mysql



                              Thanks for helping

                              • 12. Re: How to use UTF-8 characters like german umlauts or others in view pages
                                hispeedsurfer.hispeedsurfer.gmx.net

                                HI,


                                I know this is a old post. But for other in future.



                                <?xml version="1.0" encoding="ISO-8859-1"?>
                                <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



                                I don't know why this encoding works and utf-8 not, but with many troubles I found this for my solution.

                                • 13. Re: How to use UTF-8 characters like german umlauts or others in view pages
                                  maricool

                                  Hi, look at this: JBoss Seam UTF-8 encoding