-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a custom group model created for my project. Code available at https://zkfiddle.org/sample/nb4hk2/2-CustomGroupsModel-expand-collapse-all
Issue : Group Expand all / collapse all causing ConcurrentModificationException
Steps: Click collapse all button in the fiddle.
Expected Result - All groups should collapse
Actual Result - Only the 1st group is getting collapsed. Getting ConcurrentModificationException.
After collapsing all groups manually, clicking Expand all button also gives same exception.
Note: The code I use is evolved from https://forum.zkoss.org/question/112061/group-open-not-working-for-custom-group-model/
I'm not sure whether it is a bug or I'm missing something?
Hi vsriram92,
It's counter-intuitive, but you cannot change the children of the listbox while iterating over listbox children, or the "next" statement becomes meaningless. Closing groups cause the listbox to drop children of closed groups, opening groups cause the listbox to generate new children in these groups.
As such, you are in a situation where you are modifying the collection (by opening or closing groups) while iterating into the same collection.
A way to avoid that is to build your change list, then do all changes after reading all children, or to just go over the groups collection (which doesn't change when opening or closing a group).
private void expandCollapseAll(Component view, boolean toExpand){ Listbox listBox = (Listbox) view.getFellowIfAny("processList"); List<listgroup> groups = listBox.getGroups(); for (Listgroup listgroup : groups) { listGroupExpandCollapse(listgroup, toExpand); } notifyCollapseButton(!toExpand); }
see the modified fiddle here: https://zkfiddle.org/sample/nb4hk2/3-CustomGroupsModel-expand-collapse-all
Asked: 2020-02-18 01:39:03 +0800
Seen: 6 times
Last updated: Feb 18 '20