我是JSF的新手,我想將我的網頁國際化,以便網站訪問者通過點擊代表每個語言環境的標誌圖標,可以在各種語言之間進行切換。 我編輯了我的faces-config.xml並添加了資源包,默認語言環境和支持的語言環境。 然後我寫了一個叫做changeLang.java的bean,它應該是做後臺工作的。 當頁面evaulated我得到以下錯誤:JSF語言環境例外
index.xhtml @8,89 locale="#{changeLang.currentLocale}" Attribute did not evaluate to a String or Locale: null
技術:
JSF 2.0鑽嘴魚科2.0.2
春3.0.0
Facelets的
我
changeLang.java文件
package gui;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import javax.annotation.ManagedBean;
import javax.faces.context.FacesContext;
import org.springframework.context.annotation.Scope;
@ManagedBean
@Scope("session")
public class ChangeLang {
private Locale currentLocale;
public ChangeLang() {
this.currentLocale = FacesContext.getCurrentInstance().getApplication().getDefaultLocale();
}
public Locale getCurrentLocale() {
return this.currentLocale;
}
public ArrayList getSupportedLocales(){
ArrayList listOfSupp = new ArrayList();
Iterator locales = FacesContext.getCurrentInstance().getApplication().getSupportedLocales();
while(locales.hasNext()) {
Locale locale = locales.next();
listOfSupp.add(locale);
}
return listOfSupp;
}
public void setCurrentLocaleLanguage(String language) {
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(language));
}
}
and「using page」snippet
f:view locale="#{changeLang.currentLocale}" contentType="text/html; charset=utf-8"
完整的日誌:
An Error Occurred:
/index.xhtml @8,89 locale="#{changeLang.currentLocale}" Attribute did not evaluate to a String or Locale: null
- Stack Trace
javax.faces.view.facelets.TagAttributeException: /index.xhtml @8,89 locale="#{changeLang.currentLocale}" Attribute did not evaluate to a String or Locale: null
at com.sun.faces.facelets.tag.jsf.ComponentSupport.getLocale(ComponentSupport.java:218)
at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:119)
at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:160)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:86)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:75)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:145)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:716)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
- Component Tree
- Scoped Variables
Request ParametersName Value
None
View AttributesName Value
None
Request AttributesName Value
None
Flash AttributesName Value
None
Session AttributesName Value
None
Application AttributesName Value
csfcff [email protected]
請,你會這麼好心幫我解決這個問題?
感謝您的任何建議。
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>sk</supported-locale>
<supported-locale>ko</supported-locale>
</locale-config>
給你的faces-config(語言環境部分) – Bozho 2010-03-03 10:40:36