2011-07-07 30 views
0

我想從複選框恢復項目列表檢查,當我迭代列表檢索項目檢查指令while循環到無限的問題 這是我的代碼:while循環到無窮大,當我嘗試從selectManyCheckbox檢索檢查的項目

JSF:

<h:selectManyCheckbox value="#{TestAjax.selectedItemscheckbox}"> 
<f:selectItem itemValue="priority.pname" itemLabel="By priority" /> 
<f:selectItem itemValue="project.pname" itemLabel="By project" />  
</h:selectManyCheckbox> 

代碼:

public Class TestAjax { 

private ArrayList<String> selectedItemscheckbox; //list of checkbox used for grouping 


public ArrayList<String> getSelectedItemscheckbox() { 
    return selectedItemscheckbox; 
} 

public void setSelectedItemscheckbox(ArrayList<String> selectedItemscheckbox) { 
    this.selectedItemscheckbox = selectedItemscheckbox; 
} 


public void CreateQueryNumber() 
{ 
Iterator it= selectedItemscheckbox.iterator(); 
System.out.println("checkeddddddddddd"+selectedItemscheckbox); 

while(it.hasNext()) ===>loop to the infinity 
{ 
    System.out.println("one"+ it.toString()); 
select ="select count(jiraissue.id) as nb"; 
from ="jiraissue j ,priority pr ,project proj"; 
where="j.project=proj.id"; 
jointure="j.priority =pr.id"; 
groupBy="group by "+it.toString(); 

} 

}

回答

4

您沒有對it.next()進行任何調用。爲了解決這個問題,你可以在你的循環的末尾添加it.next():

while(it.hasNext()){ 
     .... bla bla bla .... 
     it.next(); 
    } 

或使用類似:

Object obj; 
    while((obj = it.next()) != null){ 
     .... bla bla bla .... 
    } 
+0

,謝謝你,我已經puted it.toString()而不是it.next(),這是因爲我還沒有喝咖啡還沒有:) – rym

+0

,每天早晨發生! = P – Fido

1

你是不是叫it.next()迭代器跳轉至下一個值。

while(it.hasNext()) 
{ 
    String i_str = it.next().toString(); 
    System.out.println("one"+ i_str); 
    select ="select count(jiraissue.id) as nb"; 
    from ="jiraissue j ,priority pr ,project proj"; 
    where="j.project=proj.id"; 
    jointure="j.priority =pr.id"; 
    groupBy="group by "+i_str; 
} 
0

你還在Java 1.4或更高版本?你已經在1.5或更新了,對吧?使用enhanced for loop

for (String selectedItem : selectedItemscheckbox) { 
    System.out.println(selectedItem); 
    // ... 
} 
+0

謝謝你,我想問你,通過使用這個循環有什麼優勢? – rym