@Inject
private InstanceContainer<Entity> entityDc;
@Inject
private InstancePropertyContainer<RelatedEntity> relatedEntityDc;
@Subscribe
public void onInit(InitEvent event) {
// Capture the changes of the Entity
entityDc.addItemPropertyChangeListener(propertyChangeEvent -> {
entityDc.setItem(propertyChangeEvent.getItem());
});
// Capture the changes of the inner entity RelatedEntity
relatedEntityDc.addItemPropertyChangeListener(propertyChangeEvent -> {
relatedEntityDc.setItem(propertyChangeEvent.getItem());
});
}
When I edit field1 or field2, the Table UI showing the list of entities (of type Entity) is automatically updated. However when I edit the field3, which belongs to the nested entity RelatedEntity, the Table UI doesn’t get updated. I checked with printing out messages, the event is generated on changes of field3 but the line relatedEntityDc.setItem(propertyChangeEvent.getItem()) seem not to have an effect. It seems that the “setItem” method doesn’t have an impact if nested entities get changed.
Here’s a sample project. If you try to modify the field1 or field2, the table data is updated. However updating field1 or field2 of the related entity doesn’t refresh the table.
I think the issue in Cuba code is that changes of sub-entities are not firing the event due to reference equality for change check instead of object equality. As you can see, the workaround is not nice.
The project you have attached doesn’t work correctly because the related entity instance just doesn’t exist. You need to create it somehow, for example when you create the master entity:
public class MainEntityBrowse extends MasterDetailScreen<MainEntity> {
@Inject
private DataContext dataContext;
@Subscribe
public void onInitEntity(InitEntityEvent<MainEntity> event) {
RelatedEntity relatedEntity = dataContext.create(RelatedEntity.class);
event.getEntity().setField3(relatedEntity);
}
}
Notice that the RelatedEntity instance is created using DataContext, which ensures the new instance will be saved when the screen commits.