tags:

views:

32

answers:

1

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.

+1  A: 

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"&gt;
    <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"&gt;&lt;head&gt;
    <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.

BalusC
Thanks for the above input. The result above is the one which I am looking for. However there are some differences. The characters (database) which I am getting from the jsf renderer is html encoded UTF (...;) which is rendered correctly everywhere except inside the script tag. I have included the xml tag and meta tag in which I have set the charset to utf-8 but none of this is working. Is there any server level configuration that I need to change or I have to add any page level tag??ps:- My application is deployed on was 6.1
ali
In the above test just encode (in ...; form) the data and then check what is being rendered.
ali
Are you saying that the text is stored as XML entities (e.g. `Ӓ`) in the database? Why? Please clarify the technical specifications more so that we can try to reproduce this. As far you're only describing the symptoms, but you're not giving anything feasible to work with. How *exactly* are the characters stored? How *exactly* are you retrieving them? How *exactly* are you displaying them? Update your question to include a complete example like I did above in my answer.
BalusC