我有一个变量(名为myChoice),我不能在程序中保存它的值,这是代码。
JSF: <h:form id="main">
<p:growl id="msgs" />
<h:selectOneMenu value="#{Bean.myChoice}">
<f:selectItems value="#{Bean.getMyListKPI()}" />
<p:ajax event="valueChange" update="f1,f2,f3"
listener="#{Bean.selectChangeHandler}"></p:ajax>
</h:selectOneMenu>
</h:form>
My code JAVA:
public List<SelectItem> getMyListKPI() {
FindKpi fkpi =new FindKpi();
if (MyListKPI == null) {
MyListKPI = new ArrayList<SelectItem>();
for (String val : fkpi.FindListKpi(iduser)) {
MyListKPI.add(new SelectItem(val));
}
}
return MyListKPI;
}
public void selectChangeHandler() { //mychoice has the right value
form1Visible = false;
form2Visible = false;
form3Visible = false;
if (this.myChoice.equals("Number Of Issues in Status")) {
this.setMyChoiceInter(myChoice);
form1Visible = true;
} else if (this.myChoice.equals("Response Time")) {
form2Visible = true;
} else if (this.myChoice.equals("Environment Availibility")) {
form3Visible = true;
}
}
public String query()
{
if (this.myChoice.equals("Number Of Issues in Status")) { //myChoice always NULL
//....
}
}
更新我已经将myChoice声明为静态的,它工作了!:)
将管理bean Bean
(具有myChoice
属性)设置为请求作用域