このコードは完全に単純化されていますが、私の問題を再現しています。
BackingBean.java
public String reload(){
System.out.println(FacesContext.getCurrentInstance()
.getViewRoot().getLocale());
return "test";
}
public void setLocale(){
System.out.println("locale changed!");
FacesContext.getCurrentInstance()
.getViewRoot().setLocale(Locale.FRANCE);
}
test.xhtml
<h:form>
<h:commandLink action="#{backingBean.reload}" value="reload page"/>
</h:form>
<h:form>
<h:commandLink action="#{backingBean.setLocale}" value="change locale"/>
</h:form>
出力:
en
locale changed!
fr_FR
en
ロケールを変更してからメソッドを2回呼び出すとreload
、ロケールはデフォルトにリセットされますen
。locale
リセットの理由は何ですか?また、他のページに転送する場合にのみ発生します。reload
メソッドをに変更してもvoid
、ロケールはfr
そのままです。
public void reload(){
System.out.println(FacesContext.getCurrentInstance()
.getViewRoot().getLocale());
}
出力:
en
locale changed!
fr_FR
fr_FR
ただし、2回転送すると、ロケールはに戻されますen