Mike
Mike

Reputation: 217

CUBA : injecting a datasource in a frame dynamically

Relates to question CUBA : entity inheritance

I have:
- Customer entity (name, email)
- Company extends Customer (industry)
- Person extends Customer (firstName, lastName)

I would like to design following screens:
- CustomerEditFrame, no datasource defined
- CompanyEditScreen embedding CustomerEditFrame
- PersonEditScreen embedding CustomerEditFrame

Then I need to define the datasource of the frame:
- In CompanyEditScreen, a companyDs needs to be defined for the frame
- In PersonEditScreen, a personDs needs to be

Options I see:
1) In all screens embedding the frame, use the same datasource name (e.g customerDs) so that it can be injected in the frame : confusing, if I have a Company Datasource I would like to call it companyDs and not customerDs
2) From the frame, call getDsContext().get(ds_id) : nok, because name of ds changes
3) From the frame, iterate on getDsContext().getAll() and look for a datasource over a Customer class or a subclass and ensure there is only one : not safe, not sure to get the right one
4) From the screen, e.g CompanyEditScreen, assign the companyDs to the frame in the init() method : no method to do so per se

Have looked through all the samples (including sampler code). The case that is closer is the OrderEdit screen of the Sales sample which dynamically open a frame depending on the Operation type. It does not cover inheritance but the solution used is based on datasource name (1st option, which I find confusing when dealing with children classes).

How should I do ?

Upvotes: 1

Views: 434

Answers (1)

knstvk
knstvk

Reputation: 637

I would suggest passing an entity instance to the frame instead of passing or referencing the whole datasource, as explained here.

When the screen with two datasources containing the same instance (one in the screen and one in the nested frame) will be committed, there will be no any duplication because screen collects data from all dirty datasources into a single Set.

Upvotes: 1

Related Questions