开发者

JSF EL expression renders question marks (?) for Chinese characters inside JavaScript

I am using an EL expression inside JavaScript for rendering Chinese value.

alert('#{bundle.chinese}');

But it renders question marks (?) instead of actual characters.

When I use it outside a script tag in the same XHTML page, e.g.

<p>#{bundle.chinese}</p> 

It renders the right chinese开发者_高级运维 Characters. View source shows the html UTF encoded values &....;).

I am using JSF on Facelets.


Sorry, I can't reproduce this with Mojarra 2.0.2 on Tomcat 6.0.20. Here's the JSF page I used:

<!DOCTYPE html>
<html 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
    <f:loadBundle basename="com.example.i18n.text" var="bundle" />
    <h:head>
        <title>test</title>
        <script>alert('#{bundle.chinese}');</script>
    </h:head>
    <h:body>
        <p>#{bundle.chinese}</p>
    </h:body>
</html>

And here is the contents of com/example/i18n/text.properties.

chinese=\u6C49\u8BED\uFF0F\u6F22\u8A9E\u002C\u0020\u534E\u8BED\uFF0F\u83EF\u8A9E\u0020\u006F\u0072\u0020\u4E2D\u6587

The generated HTML source is:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
    <title>test</title>
    <script>alert('汉语/漢語, 华语/華語 or 中文');</script></head><body>
    <p>汉语/漢語, 华语/華語 or 中文</p></body>
</html>

Probably you're doing some stuff a bit differently and/or using a different JSF impl/version. Aren't you somewhere hardcoding/using a non-UTF-8 character encoding? Watch the IDE settings as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜