Entity changes are not preserved in the UI when there is a deep composition relationships
Environment
Jmix version: 2.7.0
Bug Description
Entity changes are not preserved in the UI when there is a deep composition relationships
Steps To Reproduce
- Run sample project
- Navigate to
As - Create entity
Awith nameA1 - Create entity
Bwith nameB1 - Create entity
Cwith nameC1 - Create entity
Dwith nameD1 - Save everything Now you should have the following relationships: A1 > B1 > C1 > D1
- Open edit view for
A1 - Open edit view for
B1 - Open edit view for
C1 - Open edit view for
D1 - Change its name to
D2 - Save all but
A1, keep it open - Open edit view for
B1again - Open edit view for
C1again - The name of the
Dentity remainsD1in the UI
Current Behavior
The name of the D entity remains D1 in the UI
Expected Behavior
The name of the D changes to D2 in the UI
Notes
After step 13, only C1 and D1 are marked as modified in the a-detail-view context, but not B1. So when opening the B1 view again it provides the original B1 which does not have any changes in C1 and D1 .
Sample Project
There is a workaround: in each intermediate detail view (except the root and the last ones), add the listener for the next level entity changes to mark the current entity instance modified.
This is shown in UI Samples: https://demo.jmix.io/ui-samples/sample/composition-2-levels?tab=TerminalDetailView.java
For the attached project, this means adding the following handlers:
public class BDetailView extends StandardDetailView<B> {
@ViewComponent
private DataContext dataContext;
@Subscribe(id = "csDc", target = Target.DATA_CONTAINER)
public void onCsDcItemPropertyChange(final InstanceContainer.ItemPropertyChangeEvent<C> event) {
B b = getEditedEntity();
dataContext.setModified(b, true);
}
}
public class CDetailView extends StandardDetailView<C> {
@ViewComponent
private DataContext dataContext;
@Subscribe(id = "dsDc", target = Target.DATA_CONTAINER)
public void onDsDcItemPropertyChange(final InstanceContainer.ItemPropertyChangeEvent<D> event) {
C c = getEditedEntity();
dataContext.setModified(c, true);
}
}