You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ben Hanney <be...@hotmail.com> on 2007/05/23 13:14:45 UTC
Japanese Message Bundle not Displaying correctly with MyFaces/JSF
Hi
I'm having a display problem when using Japanese message bundles with
MyFaces/JSF. All text loaded from
bundles is garbled (read incorrectly as ISO-8859-1 at some point I
think) while static Japanese characters
in the JSP are displayed correctly.
I'm using MyFaces 1.1.4 in Tomcat 5.5 on JBoss 4.0.5GA (Mac OS X 10.4.9)
(Tomcat Connectors are all set to use URIEncoding="UTF-8"
useBodyEncodingForURI="true")
Here is small test that illustrates the problem:
1. Create a bundle text_ja.properties encoded as ISO-8859-1 using the
native2ascii tool that contains hello in Japanese.
text_ja.properties:
hello=\u201e\u00c5\u00ec\u201e\u00c7\u00ec\u201e\u00c5\u00b4\u201e
\u00c5\u00b0\u201e\u00c5\u00d8
2. Create and run this JSF enabled jsp:
hello.jsp: NB: Hello(......) Should contain Hello in Japanese characters
<%@ page language="java" contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Japanese Hello(こんにちは) Test</title>
</head>
<body>
<f:view locale="ja">
<%System.out.println("ContentType before loading bundle =
"+response.getContentType());
out.println("<p>OUT:ContentType before loading bundle =
"+response.getContentType()+"</p>");
%>
<f:loadBundle basename="bundles.text" var="text"/>
<%System.out.println("ContentType after loading bundle =
"+response.getContentType());
out.println("<p>OUT:ContentType after loading bundle =
"+response.getContentType()+"</p>");
java.util.ResourceBundle rb = java.util.ResourceBundle.getBundle
("bundles.text",
javax.faces.context.FacesContext.getCurrentInstance().getViewRoot
().getLocale());
System.out.println("ContentType after manual bundle load =
"+response.getContentType());
out.println("<p>OUT:ContentType after manual bundle load =
"+response.getContentType()+"</p>");
System.out.println("Hello in Japanese should be " + rb.getString
("hello"));
out.println("<p>OUT:Hello(こんにちは) in Japanese should be " +
rb.getString("hello")+"</p>");
%>
Hello(こんにちは) in Japanese should be <h:outputText value="#
{text['hello']}"/>
</f:view>
</body>
</html>
In Firefox 2 you get the following output:
Title: Japanese Hello(こんにちは) -- Japanese Characters in
Brackets displayed correctly
OUT:ContentType before loading bundle = text/html;charset=UTF-8
OUT:ContentType after loading bundle = text/html;charset=UTF-8
OUT:ContentType after manual bundle load = text/html;charset=UTF-8
OUT:Hello(こんにちは) in Japanese should be „Åì„Çì„Å
´„Å°„ÅØ -- Japanese Characters in Brackets are correct,
bundle characters are garbled
Hello(こんにちは) in Japanese should be „Åì„Çì„Å
´„Å°„ÅØ -- Japanese Characters in Brackets are correct,
bundle characters are garbled
In STDOUT you get the following output:
11:24:20,403 INFO [STDOUT] ContentType before loading bundle = text/
html;charset=UTF-8
11:24:20,411 INFO [STDOUT] ContentType after loading bundle = text/
html;charset=UTF-8
11:24:20,439 INFO [STDOUT] ContentType after manual bundle load =
text/html;charset=UTF-8
11:24:20,464 INFO [STDOUT] Hello in Japanese should be こんにち
は -- Japanese Hello is displayed correctly
Googling I found people with similar issues with Struts that were
resolved by using a filter so added this filter:
public void doFilter( ServletRequest request,
ServletResponse response,
FilterChain filterChain )
throws IOException, ServletException
{
myLog.info(this.getClass().getName() + ": Request Encoding was
" + request.getCharacterEncoding());
request.setCharacterEncoding("UTF-8");
myLog.info(this.getClass().getName() + ": Request Encoding set to
" + request.getCharacterEncoding());
myLog.info(this.getClass().getName() + ": Response Encoding was "
+ response.getCharacterEncoding());
myLog.info(this.getClass().getName() + ": Response ContentType
was " + response.getContentType());
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
myLog.info(this.getClass().getName() + ": Response Encoding set to
" + response.getCharacterEncoding());
myLog.info(this.getClass().getName() + ": Response ContentType set
to " + response.getContentType());
filterChain.doFilter( request, response );
myLog.info(this.getClass().getName() + ": Request Encoding is " +
request.getCharacterEncoding());
myLog.info(this.getClass().getName() + ": Response Encoding is " +
response.getCharacterEncoding());
myLog.info(this.getClass().getName() + ": Response ContentType
was " + response.getContentType());
}
But this had no effect on the garbling and in the jboss logs this can
be seen:
[UTF8EncodingFilter] Request Encoding was null
[UTF8EncodingFilter] Request Encoding set to UTF-8
[UTF8EncodingFilter] Response Encoding was ISO-8859-1
[UTF8EncodingFilter] Response ContentType was null
[UTF8EncodingFilter] Response Encoding set to UTF-8
[UTF8EncodingFilter] Response ContentType set to text/
html;charset=UTF-8
[UTF8EncodingFilter] Request Encoding was UTF-8
[UTF8EncodingFilter] Request Encoding set to UTF-8
[UTF8EncodingFilter] Response Encoding was UTF-8
[UTF8EncodingFilter] Response ContentType was text/html;charset=UTF-8
[UTF8EncodingFilter] Response Encoding set to UTF-8
[UTF8EncodingFilter] Response ContentType set to text/
html;charset=UTF-8
[ServletCacheAdministrator] Created new instance of
ServletCacheAdministrator
[ServletCacheAdministrator] Created new application-scoped cache at
key: __oscache_cache
[[/app]] No state saving method defined, assuming default server
state saving
[STDOUT] ContentType before loading bundle = text/html;charset=UTF-8
[STDOUT] ContentType after loading bundle = text/html;charset=UTF-8
[STDOUT] ContentType after manual bundle load = text/html;charset=UTF-8
[STDOUT] Hello in Japanese should be こんにちは -- Japanese
characters are displayed correctly
[MyfacesConfig] No context init parameter
'org.apache.myfaces.PRETTY_HTML' found, using default value true
....
[MyfacesConfig] No context init parameter
'org.apache.myfaces.CHECK_EXTENSIONS_FILTER' found, using default v
[UTF8EncodingFilter] Request Encoding is UTF-8
[UTF8EncodingFilter] Response Encoding is UTF-8
[UTF8EncodingFilter] Response ContentType was text/html;charset=UTF-8
[UTF8EncodingFilter] Request Encoding is UTF-8
[UTF8EncodingFilter] Response Encoding is UTF-8
[UTF8EncodingFilter] Response ContentType was text/html;charset=UTF-8
The response is initially defaulting to ISO-8859-1 and I am sure this
has something to do with the garbling.
Can anyone shed some light on this? I'm fairly new to JSF in general
and I've just about reached my limit at this point!
Cheers,
Ben