Editor screen delete list entities before add new entities programmatic

Hello community,

I have a editor screen with a list of related entities and I need to delete the existing entities before I add new entities into the list programmatic.

current entity and related entities are based on StandardEntity and the datasource for the related entities is a nested collection-datasource.

I have an import button which loads the new entities into the list with:
itemsDs.addItem(pli);

at the end I do an:
itemsDs.refresh();

The adding works and the screen will be refreshed afterwards, but even I try to delete the old entities before, I have both (old and new) entities in the list when I do a second import.

For deleting I have tried to remove the existing entities before I add the new ones with:

	    for (PartlistItem delPli : itemsDs.getItems()) {
	    	itemsDs.removeItem(delPli);
	    }

But got the following exception:

java.util.ConcurrentModificationException
at java.util.Vector$Itr.checkForComodification(Vector.java:1210)
at java.util.Vector$Itr.next(Vector.java:1163)
at org.eclipse.persistence.internal.indirection.jdk8.IndirectList$1.next(IndirectList.java:82)
at java.util.Collections$UnmodifiableCollection$1.next(Collections.java:1042)
at de.smkc.cuba.fdl.web.partlist.PartlistEdit.loadPartlistItems(PartlistEdit.java:223)
at de.smkc.cuba.fdl.web.partlist.PartlistEdit.onButtonImportClick(PartlistEdit.java:166)

Looks I doing it wrong…

Any suggestions and hints are desirable.

Studio: 6.8.5 - Platform: 6.8.8

Thanks in advance
Steven

This can be a random guess, but did you commit() changes after removeItem() and before refresh ds?

Hi Ivan,

the exception occurs already by removing the item in the for-loop…
I haven’t a change to do a commit()

CU
Steven

Hi,

this is the problem you are facing: https://stackoverflow.com/questions/8104692/how-to-avoid-java-util-concurrentmodificationexception-when-iterating-through-an

Take the first suggested solution, it should do the trick…

1 Like

Hi Mario,

thanks, you are right. Just need to loop afterwards, since DataSource has no ‘removeAll’ method :slight_smile:

CU
Stefan