2011-07-07 60 views
0

我有一個奇怪的錯誤,在同一個bean中,我使用兩次從另一個bean傳遞過來的相同的完整性,在第一種情況下,正確的值,在第二種情況下始終爲NULL。 我'使用JSF2一次包含正確值的值另一次在同一個Bean中包含NULL

MY 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> 
+0

您可以包括對myChoice領域的getter和setter方法?它使用this.myChoice(字段本身)的時間以及無法使用this.getMyChoice()(該字段的getter)的時間 - 問題可能出在你的getter ,儘管你怎麼會把這件事搞砸,我不知道。 –

+0

@Anthony Grist,我已經在第二次嘗試this.myChoice,同樣的問題仍然存在:( – rym

+0

你使用的是JSF1還是JSF2? – Dejell

回答

0

聲明你的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> 
+0

我已經改變了bean來查看,但是出現以下錯誤:com.sun.faces.mgbean.ManagedBeanPreProcessingException:Erreur inattendue lors du traitement du beangéréTestAjax – rym

相關問題