Hi all,
I am trying to understand how the dataContext works in greater detail. I read the documentation and I understand the concept. But I am unsure about automatic merging of entities in edit screens.
When I open an edit screen and debug into the dataContext I can see there are some entities in the context, how do these get added by Jmix? Is it the editedEntity + all direct compositions?
For example: I have an entity Company and that has a 1:1 composition of CEOInformation with a name and salary and also a 1:1 composition of an Address entity. The demands of our customers is not having to open popups for every sub-entity but to have a big edit screen with the fields of the Address all present.
So I made the screen with data components for all three entities and made forms and connected the fields to the properties. But the Address changes do not get saved because I saw that it is not in the dataContext. My thought is that compositions that go deeper than one level are not put there automatically?
How can I tackle this problem. I was thinking about merging all needed entities manually to the dataContext in “onBeforeShow”. But what else do I need to do? Put the resulting entity of the merge also in the edited entity like:
getEditedEntity().getCeoInformation.setAddress(dataContext.merge(getEditedEntity().getCeoInformation().getAddress())
And how does the dataComponent/loader notice that’s that the fields on the screen change the merged object?
My idea sounds a bit too complicated so I was thinking I am not getting the whole concept of the dataContext. In short: how to deal with compositions of more than one level of depth?
Thanks for any ideas!
Example of my data setup:
<data>
<instance id="companyDc"
class="com.test.domain.Company">
<fetchPlan extends="company-edit-fetch-plan"/>
<loader/>
<instance id="ceoInfoDc" property="ceoInfo">
<instance id="addressDc" property="ceoAddress"/>
</instance>
</instance>
</data>