I have a strange problem when I use filters in a table (FilteringTable addon to be precise) and edit multiple rows, only the first row gets committed.
I make call to commit() on my buffered fields like this:
for (Field field : fields) {
field.commit();
}
but after the second field is committed, the list seem to change and due to the modCount, a ConcurrentModificationException is thrown. What gives? There is a “new” list of fields now, seemingly to be the other rows unchanged.
Example:
I have a table with 7 editable columns and put a filter on let’s say the second column
I select three rows and edit them (yes, in this application you are able to edit any number of rows)
I give new values for each item on the second column
When I click for commit() the result is that only the first row has the new value I gave, the other two rows are left unchanged.
Why does the list change? This only happens in commit(). If I iterate over the fields normally (eg. update the service layer before commit()), everything seems fine.
It seems like my createField() method is called again during the first commit() because filterAll() in the overridden setValue() method is called in the IndexedContainer class. A call to filterAll() means an update of the internal data structures (doFilterContainer()), which means the rest of the items in the list will be “reset”. This also answers the question why it works without filters.
However, I still do not know exatly how to solve this issue…
I’m going to try to remove all filters from the modified items that are being committed.
To make sure all your fields are committed, you can repackage them in another Collection;
(Field field: new ArrayList(fields)){
This new collection won’t throw a CME. Of course, this doesn’t solve the root issue, which apparently are some side-effects when committing the fields…
I did try this and got around the CME, but ran into the next problem which I stated above. It seems that the filterAll() (–IndexedContainer–) method (called during the commit() phase) is resetting all data structures, which makes it impossible for me to commit any filtered fields (yes, it does work perfectly when I commit non-filtered rows).
I don’t know how to get around this, I tried to removeAllContainerFilters() before commit, but discovered that it, in its turn, also calls filterAll(), hence resetting the data strctures.