在程序期间无法保留变量的值

时间:2011-07-20 08:00:31

标签: java jsf

我有一个变量(名为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>

我的代码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声明为静态且有效! :)

1 个答案:

答案 0 :(得分:0)

简单地使托管bean BeanmyChoice属性)请求范围。