Skip to main content

JSF 2.0 utf-8

12 replies [Last post]
gabox01
Offline
Joined: 2007-04-22

Hi,

I have an UTF-8 encoded resource bundle, and i'm using the following configuration to access the resourcebundle by mojarra.

packageName.messages
msgs

The problem is that the characters aren't encoded right. How can i enable utf-8 support in mojarra?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
arjan_t
Offline
Joined: 2010-06-01

> Figured it out.
>
> I have debugged this line, and at this point, no
> matter what locale is set, characters are screwed up.
> I have faced this problem before in my applications,
> and the solution was this article:
>
> http://www.thoughtsabout.net/blog/archives/000044.html

Interesting article indeed. This same problem is also explained here with a little more elaborate example:

http://jdevelopment.nl/java/internationalization-jsf-utf8-encoded-proper...

It's a shame though that JSF doesn't provide this out of the box. It's hard to wrap one's head around the rationale behind not providing UTF-8 support at a location where it probably matters most.

tzwoenn
Offline
Joined: 2005-07-01

Is your messages properties file in key=value or XML format?

The docs [1] say, the first one's encoding is fixed to ISO-8859-1, while in the later one UTF-8 is preferred, but can use other as well.

[1] http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html

gabox01
Offline
Joined: 2007-04-22

It is in properties format.

I have debugged the source, and in RenderKitImpl.java, i found this:

if (characterEncoding == null) {
characterEncoding = RIConstants.CHAR_ENCODING;
}

At this point, characterEncoding is UTF-8. Yet, on the page, characters are gibberish.

gabox01
Offline
Joined: 2007-04-22

Figured it out.

In ApplicationResourceBundle.java, there is a method getResourceBundle(Locale).

It loads the resourcebundle like this:

bundle = ResourceBundle.getBundle(baseName, locale, loader);

I have debugged this line, and at this point, no matter what locale is set, characters are screwed up. I have faced this problem before in my applications, and the solution was this article:

http://www.thoughtsabout.net/blog/archives/000044.html

Jim Driscoll

So, as tzwoenn, pointed out, the problem was that you were using
properties files, which are Latin 1 only, and this is enforced by the
JDK. The workaround would be to use an XML formatted properties file,
apparently (though I haven't tested this).

Not sure what the appropriate Mojarra fix is for this - is it
appropriate for JSF to allow UTF-8, despite the Latin 1 requirement?
As far as I can tell, the spec doesn't specify this behavior, though you
could argue it's implicit in the reliance on the properties file.

Please update the 1206 bug you filed with the new info - we may have to
punt this over to the JSF expert group for a mod to the standardization
as well.

Jim

On 7/17/09 1:30 AM, webtier@javadesktop.org wrote:
> Figured it out.
>
> In ApplicationResourceBundle.java, there is a method getResourceBundle(Locale).
>
> It loads the resourcebundle like this:
>
> bundle = ResourceBundle.getBundle(baseName, locale, loader);
>
> I have debugged this line, and at this point, no matter what locale is set, characters are screwed up. I have faced this problem before in my applications, and the solution was this article:
>
> http://www.thoughtsabout.net/blog/archives/000044.html
> [Message sent by forum member 'gabox01' (gabox01)]
>
> http://forums.java.net/jive/thread.jspa?messageID=356188
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

gabox01
Offline
Joined: 2007-04-22

Thanks Jim

Just realized that native2ascii tool can fix my bundles, but sure it would be better, if java could handle UTF-8 bundles out of the box.

Paulo Cesar Reis

Hi,

Have you checked the encode of the resourceBundle file? Make sure it's
encoded with UTF-8.

On 7/6/09 7:09 AM, "webtier@javadesktop.org"
wrote:

> Hi,
>
> I have an UTF-8 encoded resource bundle, and i'm using the following
> configuration to access the resourcebundle by mojarra.
>
>
> packageName.messages
> msgs
>

>
> The problem is that the characters aren't encoded right. How can i enable
> utf-8 support in mojarra?
>
> Thanks.
> [Message sent by forum member 'gabox01' (gabox01)]
>
> http://forums.java.net/jive/thread.jspa?messageID=354218
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

gabox01
Offline
Joined: 2007-04-22

Hi,

Yes, i double checked my bundle, and it is in UTF-8 for sure.

I have also done the following things:

1.

com.sun.faces.disableUnicodeEscaping true

2. CustomCharacterEncoderFilter.java

public class CustomCharacterEncodingFilter implements Filter {

public void init(FilterConfig config) throws ServletException {
}

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

public void destroy() {

}
}

None of them helps.

Paulo Cesar Reis

Hi,

Did you try in another browser/O.S? I had this kind of problem with my
VirtualMachine running firefox on windows xp sp2 and when I tried in another
combination of O.S+browser the problem just disappear, it worked for me,
give it a try (if you didn't do).

On 7/8/09 10:27 AM, "webtier@javadesktop.org"
wrote:

> Hi,
>
> Yes, i double checked my bundle, and it is in UTF-8 for sure.
>
> I have also done the following things:
>
> 1.
>
>
com.sun.faces.disableUnicodeEscaping >
true >

>
> 2. CustomCharacterEncoderFilter.java
>
> public class CustomCharacterEncodingFilter implements Filter {
>
> public void init(FilterConfig config) throws ServletException {
> }
>
> public void doFilter(ServletRequest request, ServletResponse response,
> FilterChain chain) throws IOException, ServletException {
> request.setCharacterEncoding("UTF-8");
> response.setCharacterEncoding("UTF-8");
> chain.doFilter(request, response);
> }
>
> public void destroy() {
>
> }
> }
>
> None of them helps.
> [Message sent by forum member 'gabox01' (gabox01)]
>
> http://forums.java.net/jive/thread.jspa?messageID=354646
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

gabox01
Offline
Joined: 2007-04-22

I tried it with Win7 RC1, on both firefox and chrome. My collage also tried it on OSX, with safari. Same issue.

gabox01
Offline
Joined: 2007-04-22

Still got the issue. If you have any idea, please let me know.

Paulo Cesar Reis

Hi,

Sorry but no clue anymore, did you try to debug? To see who is setting the
encoding-type different than UTF-8.

On 7/14/09 5:45 AM, "webtier@javadesktop.org"
wrote:

> Still got the issue. If you have any idea, please let me know.
> [Message sent by forum member 'gabox01' (gabox01)]
>
> http://forums.java.net/jive/thread.jspa?messageID=355542
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net