1 2 Previous Next 15 Replies Latest reply on Jun 26, 2006 12:51 PM by cptnkirk

    Seam Booking example does not sorport chinese character

    lws688

      I tried seam booking example and found that it did not support chinese character input as real user name. Can anyone help me on this? (my seam version is 1.0.1 GA)

        • 1. Re: Seam Booking example does not sorport chinese character
          liudan2005

          this has got nothing to do with Seam. a common way to solve this problem is to write a filter like this:

          public class SetCharacterEncodingFilter implements Filter {
           public void doFilter(ServletRequest request, ServletResponse response,
           FilterChain chain) throws IOException, ServletException {
           request.setCharacterEncoding("UTF-8");
           chain.doFilter(request, response);
           }
          }
          


          • 2. Re: Seam Booking example does not sorport chinese character
            gavin.king

            Right, it really has nothing to do with Seam.

            The character set is defined in the .xhtml pages like so:

            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


            Not sure if there are other places you would need to change.

            • 3. Re: Seam Booking example does not sorport chinese character
              lws688

               

              "gavin.king@jboss.com" wrote:
              Right, it really has nothing to do with Seam.

              The character set is defined in the .xhtml pages like so:

              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


              Not sure if there are other places you would need to change.



              Thank you, Gavin. It's exciting to receive your reply. I will try to modify the charset.

              • 4. Re: Seam Booking example does not sorport chinese character
                lws688

                I tried to modify charset to UTF-8 but it still can not process chinese character input correctly. Do I have to write a filter as liudan2005 suggested?

                • 5. Re: Seam Booking example does not sorport chinese character
                  lws688

                  Special thanks to liudan2005, your solution works well.

                  • 6. Re: Seam Booking example does not sorport chinese character
                    khsiow

                    I'm pretty new to this framework. What do you do with the filter class to get it working? Thanks.

                    • 7. Re: Seam Booking example does not sorport chinese character
                      gavin.king

                      Again, this has nothing to do with Seam. You do whatever you would do in plain JSF. Try asking about this in the MyFaces forum.

                      • 8. Re: Seam Booking example does not sorport chinese character
                        gavin.king

                        A quick google search convinces me that most web frameworks today work by specifying a filter in web.xml, as said by liudan. I guess I'll add one of those to Seam. Dunno why Myfaces does not have one built in.

                        • 9. Re: Seam Booking example does not sorport chinese character
                          lws688

                           

                          "gavin.king@jboss.com" wrote:
                          A quick google search convinces me that most web frameworks today work by specifying a filter in web.xml, as said by liudan. I guess I'll add one of those to Seam. Dunno why Myfaces does not have one built in.


                          Thanks, Gavin. I have solved the problem by adding a filter in web.xml.

                          • 10. Re: Seam Booking example does not sorport chinese character

                            Adding a filter by default is not strictly a good thing. If your character set output is UTF-8 then setting the request charset to UTF-8 is the right thing. However, if your encoding isn't UTF-8, you run the risk of corrupting your output when the browser reads the content as UTF-8 when it's actually something else.

                            There is a lot of alignment with ASCII and UTF-8, however it's not perfect in all cases. I've run across subtle bugs were UTF-8 parsers aren't able to understand some extended ASCII characters. Problems like these are hard enough to track down when the framework isn't incorrectly setting content type for you.

                            What's the problem with properly setting charset in the page markup? The approach also scales to sites that have multiple charsets. The given filter would need to be extended to support charset/URI matching in order to support that case.

                            I suppose if I don't like it I don't have to use the filter. Just be aware that subtle tolls live under this bridge. Don't use without thinking.

                            • 11. Re: Seam Booking example does not sorport chinese character
                              theute

                              We should be able to setup the encoding in Seam configuration and have Seam create and add the filter if needed.

                              • 12. Re: Seam Booking example does not sorport chinese character

                                "If needed" is a bit hard to define though, since this type of filter should never be needed if all else is working properly. Seam will then need a mechanism for setting the charset on a per page basis. Certainly can be done, but is non-trivial and opens a can of worms. If you specify web-app wide settings you get enhancement requests from folks needing to change the charset for a few pages. So you then provide an override mechanism (in pages.xml maybe). Then folks have more than just a few overrides, and don't want to have to (or can't) enumerate (think a large number of generated help files with MS encoding). Another enhancement for glob or regex matching.

                                I won't stop anyone from writing the best charset filter around. However I agree with the initial assessments. There are other ways to tell a browser what charset to use. Having a webapp wide filter can introduce complexity and bugs to those using these mechanisms (how is Seam going to be able to detect my meta tag?).

                                Including this filter in the codebase as a utility is one thing. Enabling it by default is another.

                                • 13. Re: Seam Booking example does not sorport chinese character
                                  theute

                                  By "if needed", i meant if configured by the developer. So i meant to have the filter as a utility (ie: if people need it, they shouldn't have to write it). But i said that based on the assumption that the filter was required. It is not obvious now that you say it.

                                  CptnKirk, you seem to be the most knowledgeable on this subject here, what would you recommend ?

                                  And what do you mean by: " this type of filter should never be needed if all else is working properly". Do you know what is broken so that this filter is required ?

                                  Thanks for your input !

                                  • 14. Re: Seam Booking example does not sorport chinese character
                                    lws688

                                    I believe that this problem is caused by a bug in FaceletViewHandler. I replaced the jsf-facelets.jar with a new one and removed the filter from the web.xml. Then I redeployed the booking example and tested it. I found that it could process and display chinese character correctly.

                                    1 2 Previous Next