cuba-platform / documentation

CUBA Platform Documentation
https://www.cuba-platform.com
Creative Commons Attribution 4.0 International
26 stars 45 forks source link

How to obtain instance of DataContext outside of Screen controller #714

Closed alexbudarov closed 4 years ago

alexbudarov commented 4 years ago

Environment

Description of the bug or enhancement

Example case - https://www.cuba-platform.com/discuss/t/entitylistener-not-affecting-an-instance-in-a-nested-graph-in-a-standardeditor/12708/16

Developer automatically creates new entities in a UI component. To merge them to data context, we need access to data context from component.

It takes some time to find that you can get DataContext by screen with this method:

DataContext dataContext = UiControllerUtils.getScreenData(screenOrFrame).getDataContext();

// or from UI component
DataContext dataContext = UiControllerUtils.getScreenData(getFrame().getFrameOwner()).getDataContext();

I think it worth short mentioning on documentation page.