JSF按钮没有';更新HTML语言属性
我在我的JSF页面上实现了如下内部化:JSF按钮没有';更新HTML语言属性,jsf,localization,internationalization,Jsf,Localization,Internationalization,我在我的JSF页面上实现了如下内部化: <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:pt=&q
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
xmlns:p="http://primefaces.org/ui">
<p:outputPanel id="menupanel">
</h:form>
<p:commandButton value="FI" pt:aria-label="Suomeksi" actionListener="#{language.countryLocaleCodeChanged}" #{view.locale.language eq 'fi'? 'ws-lang-selected' : ''}" update="menupanel"/>
<p:commandButton value="SV" pt:aria-label="På Svenska" actionListener="#{language.countryLocaleCodeChanged}" #{view.locale.language eq 'sv'? 'ws-lang-selected' : ''}" update="menupanel"/>
<p:commandButton value="EN" pt:aria-label="In English" actionListener="#{language.countryLocaleCodeChanged}" #{view.locale.language eq 'en'? 'ws-lang-selected' : ''}" update="menupanel"/>
</h:form>
</p:outputPanel>
</ui:composition>
似乎这个问题的唯一答案是将update=“@all”标记添加到commandButton
提供了更新lang标记的方法,但它也刷新了整个页面,因此不是最佳解决方案,但它可以工作
<f:view locale="#{language.localeCode}">
@ManagedBean(name = "language")
@SessionScoped
public class LanguageController implements Serializable {
private SessionVariablesBean sessionVariables;
private String localeCode = "fi_FI";
public String getLocaleCode() {
return localeCode;
}
public void setLocaleCode(String localeCode) {
this.localeCode = localeCode;
}
public String getLang() {
return this.localeCode.split("_")[0];
}
public void countryLocaleCodeChanged(ActionEvent e) {
String newLocaleValue = e.getComponent().getAttributes().get("value").toString();
//System.out.println("Locale: " + newLocaleValue);
String kieli = "FI";
if (newLocaleValue.equals("FI")) {
newLocaleValue = "fi_FI";
kieli = "FI";
localeCode = "fi";
}
if (newLocaleValue.equals("SV")) {
newLocaleValue = "sv_SE";
kieli = "SE";
localeCode = "sv";
}
if (newLocaleValue.equals("EN")) {
newLocaleValue = "en_EN";
kieli = "EN";
localeCode = "en";
}
//loop country map to compare the locale code
for (Map.Entry<String, Object> entry
: countries.entrySet()) {
if (entry.getValue().toString().equals(newLocaleValue)) {
FacesContext.getCurrentInstance().getViewRoot().setLocale((Locale) entry.getValue());
this.localeCode = newLocaleValue;
}
}
}
}