开发者

while loop to the infinity when I try to retrieve checked Item from selectManyCheckbox

I want to recuperate from a checkbox a list of item checked, the problem that when I iterate the list to retrieve the item checked the instruction while loop to the infinite this is my code:

JSF:

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

The code:

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 = select开发者_开发技巧edItemscheckbox;
}


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();

}

}


You aren't making any call to it.next(). To fix this, you can either add an it.next() at the end of your loop:

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

or use something like:

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


You are not calling it.next() to jump the iterator to the next value.

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;
}


Are you still on Java 1.4 or older? You're already on 1.5 or newer, right? Use the enhanced for loop.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜