0

Best way to clear grid

asked 2006-03-03 23:04:32 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3609985

By: tskale

I need to repopulate grid with new data. The following code attampts to remove old rows and then add new one. A message box appears with the following
exception:

Unknown exception:java.util.ConcurrentModificationException.

What is the best way to clear the grid of old data and populate with new one?

//remove old row elements
List list = rows.getChildren();
Iterator it = list.iterator();
while(it.hasNext())
{
Row r = (Row)it.next();
rows.removeChild(r);
}
//new add new row elements
row=new Row();
label = new Label("one");
row.appendChild(label);
rows.appendChild(row);



delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2006-03-04 02:32:45 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3610139

By: tomyeh

ConcurrentModificationException is thrown because removeChild changed the list of children, which you are iterating.

The list returned by getChildren is readonly, so you cannot do:

for (Iterator it = rows.getChildren().iterator(); it.hasNext();) { it.next(); it.remove(); }

Rather, you have to
for (Iterator it = new ArrayList(rows.getChildren()).iterator(); it.hasNext();) { it.next(); it.remove(); }

A bit complex. I'll see whether it is possible to make getChildren writable.

link publish delete flag offensive edit

answered 2006-03-04 02:34:56 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3610140

By: tomyeh

Sorry, the previous answer is wrong. The correct one is:

for (Iterator it = new ArrayList(rows.getChildren()).iterator(); it.hasNext();) {
rows.removeChild((Component)it.next());
}

link publish delete flag offensive edit

answered 2006-03-04 05:34:36 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3610222

By: henrichen

How about just providing some convenient APIs on Rows component.

e.g.
Rows.clear() - clears all Row.
Rows.removeRow(int index) - remove the row @index.

Just some ideas popup. Of course, make children list writable would release all these issues but also might make the program error pron. Immutable object always get some advantage in programming.

/henri


link publish delete flag offensive edit

answered 2006-03-05 15:22:11 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3611632

By: tomyeh

In upcoming 1.0.2, it is as simple as getChildren().clear().

Similary, getItems().clear() if you want to clear list items for a list box.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2006-03-03 23:04:32 +0800

Seen: 1,771 times

Last updated: Mar 05 '06

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More