我觉得价值变化监听器事件没有被触发。此外,我尝试f:valueChangeListener
并且永远不会触发事件。
我正在使用primefaces 5.3
任何帮助,请。
- 这是表格
<h:form id = "templatelocal_id" name="templatelocal_form">
<ul>
<li>
<h:selectOneMenu
id="locale_menu_id"
value="#{localizationBean.selectedLocalName}"
valueChangeListener="#{localizationBean.changeLanguage}"
onchange="submit()">
<f:selectItems
var="c"
value="#{localizationBean.localsList}"
itemLabel="#{c.displayLanguage}"
itemValue="#{c.displayLanguage}" />
</h:selectOneMenu>
</li>
</ul>
</h:form>
这是支持bean。
列出项目
@ManagedBean(name="localizationBean")
@SessionScoped
public class LocalizationBean {
private Locale locale;
private Locale selectedLocalName;
private List<Locale> localsList = new ArrayList<Locale>();
public LocalizationBean()
{
System.out.println("--------");
}
@PostConstruct
public void init()
{
System.out.println("--------Init");
locale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
localsList.add(locale);
Iterator<Locale> lsList = FacesContext.getCurrentInstance().getApplication().getSupportedLocales();
while (lsList.hasNext()) {
Locale currentLocale = lsList.next();
localsList.add(currentLocale);
}
}
public void changeLanguage(ValueChangeEvent e)
{
System.out.println("--------change");
Object newValue = e.getNewValue();
System.out.println("-----------" + newValue);
}
public Locale getLocale()
{
return locale;
}
public String getLanguage()
{
return locale.getLanguage();
}
public void setLanguage(String language)
{
locale = new Locale(language);
FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
}
public Locale getSelectedLocalName() {
return selectedLocalName;
}
public void setSelectedLocalName(Locale selectedLocalName) {
this.selectedLocalName = selectedLocalName;
}
public List<Locale> getLocalsList() {
return localsList;
}
public void setLocalsList(List<Locale> localsList) {
this.localsList = localsList;
}
}