2
votes

Using glassfish 3.1.2 with Mojarra 2.1.14.

I have following configuration in faces-config (in shared jar):

<locale-config>
    <default-locale>en</default-locale>
    <supported-locale>de</supported-locale>
    <supported-locale>en</supported-locale>
</locale-config>
<resource-bundle>
    <base-name>package.messages</base-name>
    <var>msg</var>
</resource-bundle>

msg.properties - localeValue=english
msg_de.properties - localeValue=german

Default and supported locales are retrieved correctly in belows test bean constructor.

No matter what I do, jsf always chooses german messages, even if default one is english. My jvm locale is german.

Test default locale:

An empty page printing a value from a resource bundle always prints the german de value.

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </h:head>
    <h:body>
        #{msg.localeValue}
    </h:body>
</html>

Output: "german"

Test default locale:

But the default locale is still en saving it in a session variable and printing it out:

public class SessionBean
{
    private Locale locale;

    public SessionBean()
    {
        this.locale = FacesContext.getCurrentInstance().getApplication().getDefaultLocale();
    }

    public Locale getLocale()
    {
        return this.locale;
    }
}

<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:view locale="#{sessionBean.locale}">
        <h:head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        </h:head>
        <h:body>
            #{sessionUtilsBean.locale} - #{msg.localeValue}
        </h:body>
    </f:view>
</html>

Output: "en - german" instead of "en - english"

Edit: Same locale "en" retrieved using #{bean.getViewRootLocale()} from current FacesContext.

Using "en" directly:

<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:view locale="en">
        <h:head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        </h:head>
        <h:body>
            #{msg.localeValue}
        </h:body>
    </f:view>
</html>

Output: "german"

What can be the reason?

I searched complete project, view locale is never set programmatically.

Edit:

When I remove the german properties file, the english one is used and site is displayed in english.

Edit2: Strange observations

Using an el function like omnifaces of:formatDate retrieves data in the correct (en) language.

1
To eliminate a red herring, is the filename of the German bundle file really msg.properties_de?BalusC
no that was a typo. It is msg_de.properties. Edited it and added more informations.djmj

1 Answers

0
votes

The English Properties file has to be named msg_en.properties, had the same problem.