一个值在同一Bean中一次包含正确值,另一次包含NULL



我有一个奇怪的错误,在同一个bean中,我使用相同的属性两次从另一个bean传递,在第一种情况下,属性返回正确的值,在第二种情况下总是NULL。我使用JSF2

我的JSF

:

<h:selectOneMenu value="#{ToolsKPI.myChoice}">
         <f:selectItems value="#{ToolsKPI.getMyListKPI()}" />
         <p:ajax event="valueChange" update="f1,f2,f3"
            listener="#{TestAjax.selectChangeHandler}"></p:ajax>
</h:selectOneMenu>

我的豆:

public class TestAjax implements Serializable{
   **private String myChoice**; //getters+seetters
 public void selectChangeHandler() {   //in this case myChoice contain the right value
  form1Visible = false;
  form2Visible = false;
  form3Visible = false;
  if (this.myChoice.equals("Number Of Issues in Status"))
  {    System.out.println("kpi------"+this.myChoice);
     form1Visible = true;
  }
  else if (this.myChoice.equals("Response Time"))
     form2Visible = true;
  else if (this.myChoice.equals("Number of Issue between to Status"))
     form3Visible = true; 
}


public String CreateQueryNumber()
{
Iterator it= selectedItemscheckbox.iterator();
  Iterator it2= selectedItemscheckbox.iterator();
      String grouping="";
       String selecting="";
      String group="";

while(it.hasNext())
{
 selecting=selecting +","+it.next().toString();  
 System.out.println("selecting---"+ selecting);
}
while(it2.hasNext())
{
 grouping=grouping+it2.next().toString()+",";
 System.out.println("grouping---"+ grouping);
}
 int endString =grouping.length()-1;
 group= grouping.substring(0,endString) ;
 **System.out.println("choice"+this.getMyChoice()); //in this case it's NULL!!!!!**
 try{
   if (myChoice.equals("Number Of Issues in Status"))
   {  
      System.out.println(myChoice);
    select ="select count(jiraissue.id) as nb "+selecting;
   from =" from  jiraissue ,priority  ,project,issuestatus  ";
   where=" where jiraissue.project=project.id ";
   jointure=" and jiraissue.issuestatus=issuestatus.id and jiraissue.priority =priority.id and issuestatus.pname="+"'"+this.getMyChoiceStatus()+"' ";
   groupBy=" group by "+group;
   sql =select+from+where+jointure+groupBy+" ;";
            return sql;
 }
   if(myChoice.equals("Response Time"))
    System.out.println(myChoice);
   {
   select ="select AVG(jiraissue.id) as nb "+selecting;
   from =" from  jiraissue ,priority  ,project,issuestatus  ";
   where=" where jiraissue.project=project.id ";
   jointure=" and jiraissue.issuestatus=issuestatus.id and jiraissue.priority =priority.id and issuestatus.pname="+"'"+this.getMyChoiceStatus()+"' ";
   groupBy=" group by "+group;
   sql =select+from+where+jointure+groupBy+" ;";
    System.out.println("sqlKPI2"+sql);
    return sql;
}

}

FacesConfig

<managed-bean>
<managed-bean-name>TestAjax</managed-bean-name> 
<managed-bean-class>DAOKPI.TestAjax</managed-bean-class> 
<managed-bean-scope>request</managed-bean-scope>
  <managed-property>
   <property-name>myChoice</property-name>
   <property-class>java.lang.String</property-class>
   <value>#{ToolsKPI.myChoice}</value>
 </managed-property>   
</managed-bean>

像这样在作用域中声明bean作为视图:

<managed-bean>
<managed-bean-name>TestAjax</managed-bean-name> 
<managed-bean-class>DAOKPI.TestAjax</managed-bean-class> 
<managed-bean-scope>view</managed-bean-scope>
  <managed-property>
   <property-name>myChoice</property-name>
   <property-class>java.lang.String</property-class>
   <value>#{ToolsKPI.myChoice}</value>
 </managed-property>   
</managed-bean>

相关内容

  • 没有找到相关文章

最新更新