I have an Order Edit screen that also displays related Order Items in a table.
This Order Items table is bound to dataContainer (CollectionContainer) named “orderItmesDc”
I am trying to programmatically clear the Order Items being displayed in table.
I am using the following code :
orderItmesDc.getMutableItems().clear();
But when the user saves the Order record, I am seeing that the Order Items are still there.
Looking like the clear() method does not actually remove items from the committed list.
How do I accomplish this ?
How do I allow user to clear items in table so that when the record is saved, they are truly removed ?
When you do orderLinesDc.getMutableItems().clear(), the collection is cleared in the Order entity and in the linked UI components like table. But the OrderLine instances are not marked as deleted, and since OrderLine is the owning side of the relationship (it holds the reference to Order), nothing happens in the database, even though Order.orderLines collection becomes empty.
In order to remove items from the database, you have to tell DataContext about it: