tags:

views:

724

answers:

2

Does anyone know how to remove Treeitems from a Treechildren node in ZK? I have tried using an iterator and removeChild but a ConcurrentModificationException!

List<Treeitem> myTreeItems = treechildren.getChildren();

Iterator<Treeitem> iterator = myTreeItems.iterator();

while (iterator.hasNext()){
   myItem = (Treeitem)iterator.next();
   parent.removeChild(myItem);
}

Any ideas?

+2  A: 

That is not the correct way to remove the items, you need to do something like this.

while (parent.getItemCount() > 0) {
   parent.removeChild(parent.getFirstChild());
}

This will provide the functionality that you require!

More details on using the Tree component are available here.

Tim
Thanks, worked like a charm!
Justin.Eckner
+1  A: 

As what I saw in your case you want to remove all components which are all attached on a treechildren. I think the fastest way is:

treechildren.getChildren().clear();

just operate the result like a java.util.List.

Zanyking