java h:selectOneMenu 更改事件与 p:ajax
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10486683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
h:selectOneMenu change event with p:ajax
提问by Eric
I am trying to get the value from on change in h:selectOneMenu using p:ajax. But I am getting null value always, dont know whats wrong below is the code.
我正在尝试使用 p:ajax 从 h:selectOneMenu 的变化中获取值。但是我总是得到空值,不知道下面的代码有什么问题。
<h:form>
<h:selectOneMenu id="selectMenu" value="#{userHomeController.gymsSelectType}">
<f:selectItem itemLabel="Close to me" itemValue="closest" />
<f:selectItem itemLabel="Visited by me" itemValue="visited" />
<p:ajax process="selectMenu" listener="#{userHomeController.selectMenuListener}" event="change" update=":home-form:panel" />
</h:selectOneMenu>
</h:form>
and the bean class is
而bean类是
public void selectMenuListener() {
System.out.println("-------- >> " + gymsSelectType); // here null coming
if (gymsSelectType.equals("a")) {
//
} else {
//
}
}
this is a viewscoped class. and below setter for the variable gymsSelectType is also prints null
这是一个视图范围的类。变量gymsSelectType 的setter 也打印为null
public void setGymsSelectType(String gymsSelectType) {
System.out.println("------------ >> "+gymsSelectType);
this.gymsSelectType = gymsSelectType;
}
回答by alpha2011
Have your tries this
让你试试这个
<p:ajax process="@this" listener="#{userHomeController.selectMenuListener}" event="change" update=":home-form:panel" />
回答by Germanus
Try this
试试这个
<p:ajax partialSubmit="true" listener="#{userHomeController.selectMenuListener}" event="change" update=":home-form:panel" />
<p:ajax partialSubmit="true" listener="#{userHomeController.selectMenuListener}" event="change" update=":home-form:panel" />