我想从复选框中恢复选中的项目列表,当我迭代列表以检索选中的项目时,指令while循环到无限的问题这是我的代码:
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();
}
}
您没有对它进行任何调用。要解决这个问题,您可以在循环末尾添加it.next():
while(it.hasNext()){
.... bla bla bla ....
it.next();
}
或者像
Object obj;
while((obj = it.next()) != null){
.... bla bla bla ....
}
调用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;
}
您还在使用Java 1.4或更早的版本吗?你已经是1.5或更高版本了,对吧?使用增强的for循环。
for (String selectedItem : selectedItemscheckbox) {
System.out.println(selectedItem);
// ...
}