日期:2014-05-20  浏览次数:20531 次

JSF中如何用程序更改语言环境?
我的代码:
JSF中的代码:
  <h:form>
  <h:commandLink actionListener="#{FuncBean.changLangEnv}" value="中文" />
  <h:outputLabel value=" "/><h:outputLabel value=" "/>
  <h:commandLink actionListener="#{FuncBean.changLangEnv}" value="English" />
  </h:form>
事件监听函数中的代码:
  public void changLangEnv(ActionEvent ae){
  HtmlCommandLink hlink=(HtmlCommandLink)ae.getComponent();
  String lang=(String)hlink.getValue();
  if(lang.equals("English")){
  FacesContext.getCurrentInstance().getApplication().setDefaultLocale(new Locale("en_US"));
  }else if(lang.equals("中文")){
  FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale("zh_CN"));
  }
   
  }
编译通过,运行没反应。
请大家指教,另外请问从哪里可下载jsf的api参考

------解决方案--------------------
顶一下,
FacesContext.getCurrentInstance().getViewRoot().setLocale(Locale.US);
------解决方案--------------------