6 Replies Latest reply on Jul 2, 2012 3:20 AM by chem_euegene

    Reading messages from properties file in UTF-8 on JSF 2.0 page

    chem_euegene

      I have a problem with displaying messages on JSF 2.0 page in correct encoding. I store my messages files (messages.properties and messages_ru.properties) in UTF-8 encoding.

      In faces config I have following settings:

      <application>
              <locale-config>
                  <default-locale>en</default-locale>
                  <supported-locale>ru</supported-locale>
              </locale-config>
              <resource-bundle>
                  <base-name>ru.dpop.auto.i18n.Messages</base-name>
                  <var>msgs</var>
              </resource-bundle>
      </application>
      

       

      In the class ru.dpop.auto.i18n.Messages I read properties.file:

      bundle = new PropertyResourceBundle(new InputStreamReader(stream, "UTF-8")
      

       

      My JSF page have following structure:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html lang="#{localeBean.language}" xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core">
      <f:view locale="#{localeBean.locale}">
          <h:head>
              <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
          </h:head>
          <h:body>
          #{msgs.someText}
          </h:body>
      </f:view>
      </html>
      

       

      But I instead of expected russian symbols I see something like this: Ð&#155;огин

       

      I explored this problem and found that I see ISO-8859-1 presentation insteand of UTF-8. My simple test:

      String input1 = new String("Логин");
      String input2 = new String(input1.getBytes("UTF-8"), "ISO-8859-1");
      System.out.println(input2); // Output Ð&#155;огин
      

       

       

      My question is - what I do wrong? Where is my error?

       

      I use JBoss AS 7.1.1 on Windows.

      But if I deploy this code to OpenShift - all work as expected!

       

      N.B. If I inject Messages instance in any bean and get message through messages.getObject("someText") I see correct value