0

I cannot get locales to work.

System

EAR and WAR

Glassfish: 3.12
Hibernate 4.2 - jar's on EAR and WAR
Mojarra: 2.1.11
Primefaces: 3.3
Omnifaces: 1.1

Property files in source folder:

messages_de.properties <- using german language
messages.properties <- using english language

faces-config.xml:

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

Problem:

Example the label and all other texts using the message bundle are wrong:

<?xml version="1.0" encoding="UTF-8" ?>
<!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:view locale="de">
        <h:head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        </h:head>
        <h:body>
            <h:form>
                <h:outputLabel for="postalcode" value="#{msg.postalcode_u}: *"/>
                <h:inputText id="postalcode" label="#{msg.postalcode_u}" required="true"/>
                <h:commandButton value="#{msg.save_u}"/>
            </h:form>
        </h:body>
    </f:view>
</html>

Required validation message: Default validation messages use the correct language.

Wrong message: Postalcode: Überprüfungsfehler: Wert ist erforderlich.
It should be: Postleitzahl: Überprüfungsfehler: Wert ist erforderlich.

Setup:

Glassfish 3.1.2
Mojarra 2.1.6 and also tested with 2.1.11

Edit:

1.
Using FacesContext.getCurrentInstance().getViewRoot().getLocale() to look into the same message resource bundle to display some custom faces messages does not work.

2.
I also have a second message bundle, currently also in source folder which is only accessed by the beans to display error messages:

errorMessages_de.properties
errorMessages_en.properties

Those error messages created inside the bean are localized correctly using FacesContext.getCurrentInstance().getViewRoot().getLocale()!

3.
"Forcing" german language using following config still does not work. Messages are still retrieved from messages.properties and not messages_de.properties.

<locale-config>
    <default-locale>de</default-locale>
    <supported-locale>de</supported-locale>
</locale-config>

New edit:

When i start the server i get this warning:

Unexpected exception when attempting to tear down the Mojarra runtime
java.lang.NullPointerException
    at javax.faces.component.UIViewRoot.setLocale(UIViewRoot.java:1463)
    at com.sun.faces.config.InitFacesContext.getViewRoot(InitFacesContext.java:213)
    at com.sun.faces.application.ApplicationImpl.invokeViewListenersFor(ApplicationImpl.java:2026)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:291)
    at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:335)
    at org.apache.catalina.core.StandardContext.contextListenerStop(StandardContext.java:4840)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:5584)
    at com.sun.enterprise.web.WebModule.stop(WebModule.java:527)
    at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1049)
    at com.sun.enterprise.web.WebContainer.unloadWebModule(WebContainer.java:2229)
    at com.sun.enterprise.web.WebContainer.unloadWebModule(WebContainer.java:2184)
    at com.sun.enterprise.web.WebApplication.stop(WebApplication.java:159)
    at org.glassfish.internal.data.EngineRef.stop(EngineRef.java:169)
    at org.glassfish.internal.data.ModuleInfo.stop(ModuleInfo.java:302)
    at org.glassfish.internal.data.ApplicationInfo.stop(ApplicationInfo.java:329)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.unload(ApplicationLifecycle.java:998)
    at com.sun.enterprise.v3.server.ApplicationLifecycle.undeploy(ApplicationLifecycle.java:1024)
    at org.glassfish.deployment.admin.UndeployCommand.execute(UndeployCommand.java:330)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)
    at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)
    at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:461)
    at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:212)
    at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)
    at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

Edit2:

The error message above is not relevant for the problem. See my own answer.

djmj
  • 5,579
  • 5
  • 54
  • 92
  • Can't reproduce your problem in Mojarra 2.1.10. Are you somewhere doing an explicit `UIViewRoot#setLocale()` using the wrong locale in a request scoped backing bean? That'll probably explain the odd behaviour. – BalusC Jul 31 '12 at 23:49
  • Updated to mojarra 2.1.11 and still same problem. No i am not setting it anywhere. (Had a locale session bean but deleted that for testing now.) I even created a new xhtml site with just the code i posted inside a simple form. Also deleted glassfish cache and removed apps and readded them. The example message makes no sense. Can a server setting cause that behavior? The locales definetly worked some time ago. Did not noticed when it stopped working. – djmj Aug 01 '12 at 03:15
  • Didn't you oversimplify the example and do you *actually* have a ``? – BalusC Aug 01 '12 at 11:43
  • I had before which I removed for testing. I only had a template file where I used `. My browser language is also set to `de`. – djmj Aug 02 '12 at 13:49
  • @BalusC I added some more informations what works and what not in the edit paragraph and a stracktrace from an exception which is sometimes printed. – djmj Aug 04 '12 at 23:09
  • According to the source code, `FacesContext` or `ELContext` would be `null` at that point. I suspect the `ELContext`. I'm unsure why. Are you using other frameworks together with JSF? Spring maybe? Have you registered a custom EL resolver? – BalusC Aug 05 '12 at 02:11
  • I am only using hibernate (jar's are needed on client), primefaces and omnifaces. More info in question edited. I have no custom EL resolver. I hardly changed anything. I will try to remove my apps and create a simple empty web-app and test it and report here again. – djmj Aug 05 '12 at 02:28
  • I got the error. I narrowed it down that only the file itself could be the error and then a wrong formatted utf-8 special german character. But great thanks for taking your time. – djmj Aug 07 '12 at 08:57

1 Answers1

4

There was an entry value in the properties file that escaped a german umlaut using utf-8 coding.

ü -> \u00FC

The problem was, that I missed the last C which made the properties file somehow unreadable!

Can't believe no appropriate error message was printed. If it could not be escaped why not just print the value like its done in many cases.

But that warning message is still present.

djmj
  • 5,579
  • 5
  • 54
  • 92