我無法使區域設置正常工作。JSF - 郵件包始終使用默認屬性文件
系統
EAR和WAR
Glassfish的:3.12
休眠4.2 - 在EAR和WAR JAR的
鑽嘴魚科:2.1.11
Primefaces:3.3
Omnifaces:1.1
源文件夾中的屬性文件:個
messages_de.properties < - 使用德語
messages.properties < - 使用英語
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>
問題:
例的標籤和使用消息包所有其他文本都是錯誤的:
<?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>
需要驗證消息:默認的驗證消息使用正確的語言。
錯誤消息:Postalcode: Überprüfungsfehler: Wert ist erforderlich.
它應該是:Postleitzahl: Überprüfungsfehler: Wert ist erforderlich.
設置:
Glassfish的3.1.2
鑽嘴魚科2.1.6並且還與2.1.11
測試編輯:
使用FacesContext.getCurrentInstance().getViewRoot().getLocale()
尋找到同樣的消息資源包,顯示一些自定義的信息面臨不工作。
2.
我也有一個第二消息包,目前還在源文件夾,其僅由豆訪問,以顯示錯誤消息:
errorMessages_de.properties
errorMessages_en.properties
使用FacesContext.getCurrentInstance().getViewRoot().getLocale()
在bean內部創建的錯誤消息已正確本地化!
「強制」使用下面的配置仍然不起作用德語。信息仍然從messages.properties
檢索,而不是messages_de.properties
。
<locale-config>
<default-locale>de</default-locale>
<supported-locale>de</supported-locale>
</locale-config>
新編輯:
當我啓動服務器,我得到這樣的警告:
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:
上述錯誤信息是不相關的問題。看到我自己的答案。
無法在Mojarra 2.1.10中重現您的問題。你是否在做一個明確的'UIViewRoot#setLocale()'在請求範圍的支持bean中使用錯誤的區域設置?這可能會解釋奇怪的行爲。 – BalusC 2012-07-31 23:49:54
已更新至mojarra 2.1.11,但仍然是同樣的問題。不,我沒有把它放在任何地方。 (有一個區域會話bean,但刪除了現在進行測試。)我甚至創建了一個新的xhtml站點,只是我在一個簡單的表單中發佈了代碼。還刪除了glassfish緩存並刪除了應用程序並對其進行了修改。示例消息毫無意義。服務器設置是否會導致該行爲?語言環境在一段時間之前定義了。沒有注意到它停止工作時。 – djmj 2012-08-01 03:15:09
你是不是過分簡化了這個例子,你真的*有一個''? –
BalusC
2012-08-01 11:43:38