8 Replies Latest reply on May 24, 2007 1:31 AM by Gavin King

    problem with encoding

    Anvar Sart Newbie

      i'm new to seam =)
      i use Seam-gen to generate a simple Seam project.. But there is a problem..
      When i do search in MySQL database it works fine with data written in english but every time i do search some text written in my native language it's not working. This data even shown correctly in this Seam project but every time i push search button, text in <h:inputText> became unreadable.
      In Seam Reference i found that i should put this in components.xml

      <web:character-encoding-filter encoding="UTF-8"

      but this doesn't change anything. Does anyone know how to solve this problem ?

      thank you for your aswers =)

        • 1. Re: problem with encoding
          Daniel Young Novice

          There's a few layers this can fail at. You are right that you need the character encoding filter.

          Do you know if the data is being stored/inserted correctly at the DB level? (ie- connect to MySQL using some other tool to see). MySQL allows you to specify the character encoding at a DB-wide level or on a per-table level.

          When I create tables manually I always specify "DEFAULT CHARACTER SET UTF8;" explicitly, in the name of paranoia, but you can also use "default-character-set=utf8" in the my.ini config file. This is handy if seam-gen is generating your schema for you, which I guess is probably the case.

          If everything is OK at the DB level, then I'm not sure..

          • 2. Re: problem with encoding
            Anvar Sart Newbie

            Well, i guess the problem is that pages generated as facelets(xhtml)..

            • 3. Re: problem with encoding
              Anvar Sart Newbie

              To set charset/encoding in JSP we can use

              <%@ page language="java" contentType="text/html; charset=utf-8"

              so i'm wondering is there anything like this to use in facelets

              • 4. Re: problem with encoding
                Leo Newbie

                <f:view contentType="text/html" >




                • 5. Re: problem with encoding
                  Daniel Young Novice

                  My root facelets template just has the direct meta HTML tag in it:

                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

                  The Seam blog example uses an f:view in its template.xhtml but specifies the encoding in a direct meta tag. I didn't even think f:view had such a parameter?

                  I don't even use f:view, as I never saw it in the facelets developer documentation: https://facelets.dev.java.net/nonav/docs/dev/docbook.html#gettingstarted-view-template

                  • 6. Re: problem with encoding
                    Leo Newbie


                    These is one of those things you learn because someone told you sometime :)

                    I saw this because I have just migrate my code to seam-cvs and Jboss 4.2. There, the default is contentType=xml/xhtml which turned all my javascipts as illegal things .. weird huhhhh ?

                    So, I got this tip on this forum in the "seam cvs examples on jboss 4.2"... I could not find any reference to it... and do not worry about seam doc.. this is from jsf implementation.

                    • 7. Re: problem with encoding
                      Leo Newbie

                      and my javascripts was not working w/ just this:

                      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />


                      for sure.. they just start working again when I added contentType on f:view

                      take a look bellow. This working for me.

                      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      <html xmlns="http://www.w3.org/1999/xhtml"
                      <f:view contentType="text/html">
                       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                       <link href="stylesheet/theme.css" rel="stylesheet" type="text/css" />
                       <trh:styleSheet />
                       <script type="text/javascript"
                       src="/etask/theme/com/sun/rave/web/ui/defaulttheme/javascript/formElements.js" />
                       <script type="text/javascript" src="/etask/util.js" />
                       <script type="text/javascript" src="/etask/tip.js" />
                       <body style="-rave-layout: grid">
                       <ui:include src="../layout/menu.xhtml" />
                       <ui:include src="../layout/loginout.xhtml" />
                       <div class="body"><f:facet name="aroundInvalidField">
                       <s:span styleClass="errors" />
                       </f:facet> <f:facet name="afterInvalidField">
                       <s:span>&#160;<s:message />
                       </f:facet> <ui:insert name="body" /></div>
                       <div class="footer"><a href="http://www.bittecnologia.com"
                       target="_blank">eTask (c) Bit Technologia</a></div>

                      • 8. Re: problem with encoding
                        Gavin King Master

                        AFAIK, you need it in both the meta tag and the f:view. At least I think that's what Jacob told me. I guess Facelets uses a special UIViewRoot or something.

                        I'm not sure if the Seam examples have it completely correct.

                        You would be better off asking about this stuff in the facelets forums, and checking their FAQ.