You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Kevin Roast <ke...@alfresco.org> on 2005/09/01 18:09:24 UTC

Multi-byte character form field support in MyFaces?

Hi,

We have an application where we would like users to be able to enter
multi-byte characters such as Chinese/Japanese. The user can enter the
characters fine into an <h:inputText> form field. In my bean which has a
binding to the field, I'm seeing String contents such as
"&#12365;&#12419;&#12458;&#12512;&#13018;" - where as I would hope the
String would contain the java UTF version of the characters. Does my
application require an extra "decoding" step for _every_ bean property -
or I am missing something? E.g. Do I need to tell MyFaces to decode
multi-byte String values from HTML Forms values or do I need to do
something to the page itself...?

Thanks for your time,

Kevin


Re: Multi-byte character form field support in MyFaces?

Posted by Mathias Brökelmann <mb...@googlemail.com>.
We had the same problem here entering UTF-8 characters.

That´s what we have done:

- define the content type of the page as UTF-8 (as Eric already said)
- define the attribute acceptCharset="UTF-8" for h:form
- the tricky part: the browser uses the charset which you have
specified by the attribute acceptCharset to post the input values but
the browser don´t tell it through the request header that they do it
(ask Microsoft why they don´t do it!). If the servlet container don´t
get a content encoding (which is always the case) it defaults to
ISO-8859-1. The result is that your UTF-8 multibyte chars are crumbled
if they are decoded with a wrong charset.

To make it working we use a servlet filter which simply calls
request.setCharacterEncoding("UTF-8") if the
request.getCharacterEncoding() returns null.
Place the servlet filter at the beginning of the filter chain and it
should work.

--
Mathias

2005/9/1, Eric Hedström <er...@peregrine.com>:
> This indicates the user is entering text that is not supported by the
> character set of your page. If you set the content-type of your page to
> text/html;charset=UTF-8 then the browser will respond with UTF-8 text
> and thus won't need to encode characters like this.
> 
> For example, put this at the very top of your JSP:
> <%@ page language="java" buffer="8kb"
> contentType="text/html;charset=UTF-8"%>
> 
> Eric
> 
> On 1 Sep 2005 9:09, Kevin Roast wrote:
> 
> > Hi,
> >
> > We have an application where we would like users to be able to enter
> > multi-byte characters such as Chinese/Japanese. The user can enter the
> > characters fine into an <h:inputText> form field. In my bean which has a
> > binding to the field, I'm seeing String contents such as
> > "&#12365;&#12419;&#12458;&#12512;&#13018;" - where as I would hope the
> > String would contain the java UTF version of the characters. Does my
> > application require an extra "decoding" step for _every_ bean property -
> > or I am missing something? E.g. Do I need to tell MyFaces to decode
> > multi-byte String values from HTML Forms values or do I need to do
> > something to the page itself...?
> >
> > Thanks for your time,
> >
> > Kevin
> 


-- 
Mathias

Re: Multi-byte character form field support in MyFaces?

Posted by Eric Hedström <er...@peregrine.com>.
This indicates the user is entering text that is not supported by the 
character set of your page. If you set the content-type of your page to 
text/html;charset=UTF-8 then the browser will respond with UTF-8 text 
and thus won't need to encode characters like this.

For example, put this at the very top of your JSP:
<%@ page language="java" buffer="8kb" 
contentType="text/html;charset=UTF-8"%>

Eric

On 1 Sep 2005 9:09, Kevin Roast wrote:

> Hi,
> 
> We have an application where we would like users to be able to enter
> multi-byte characters such as Chinese/Japanese. The user can enter the
> characters fine into an <h:inputText> form field. In my bean which has a
> binding to the field, I'm seeing String contents such as
> "&#12365;&#12419;&#12458;&#12512;&#13018;" - where as I would hope the
> String would contain the java UTF version of the characters. Does my
> application require an extra "decoding" step for _every_ bean property -
> or I am missing something? E.g. Do I need to tell MyFaces to decode
> multi-byte String values from HTML Forms values or do I need to do
> something to the page itself...?
> 
> Thanks for your time,
> 
> Kevin