Possible incorrect propagation of parent data source

Hi

I have a treeview and a vbox in a splitterbox on the screen. Whne the tree view selected item changes I am trying to open a frame in the vbox based on svwith the following code


    systemTreeNavigationsDs.addItemChangeListener(event -> {
    SystemTreeNavigation item = event.getItem();
    if (item != null) {
        frameBox.removeAll();
        String screen = item.getScreen();
        if (screen == null) screen = "emptyMenuScreen";
            AbstractFrame frame = openFrame(frameBox, screen, null);
            frameBox.expand(frame);
        }
    });
}

Screens are being placed in the vbox, but they are showing no data. Also a record navigator appears, but not for all screens. If I click on any of these buttons, then data appears.

If I open the screen throug menu, it shows data.

Could you please help, what I am missing here?

Thank you very much.

Hi
It looks like my issue is related to the fact, that I am opening the frame in ItemChange listener event of my systemTreeNavigationDs , therefore the newly opened frame uses current dscontext as a parent. And because the current ds is just a navigation tree entity, not related to any entity, it is unable to find any related instances.

Is it possible to open the frame without setting the current ds context as a parent to the ds context of the newly opened frame?

Thanks

Hi

Correct me if I am wrong, but it looks to me that there might be something wrong how cuba platform treats data sources.

I tried the following scenario:

  1. I created a screen with no datasources and put a splitter bar and two VBoxes in it (let’s call it the main screen).
  2. Then I created another screen which has a hierarchical datasource and a tree in it (let’s call it tree screen). The data source has a hierarchical menu structure and also a field with the ids of the screens I want to show in the right pane of splitter bar widget.
  3. I tried to embed the tree screen to the main screen with the frame widget or do it programmatically, the effect is the same;
  4. Before the tree view is added to the main screen it’s dsContext has no datasources.
  5. But after the treeview is added, the menu hierarchical data source data is added to the ds context of main screen.
  6. When I select the tree item and open the data screen on the right pane with the openFrame, the hierarchical datasource is propagated to the new frame and becomes a parent of the data screen datasource. Therefore no data is shown.

I think that the problem is that the datasource of data screen becomes a nested datasource of the hierarchical datasource of menu, and it looks like there is no way to avoid it (or at least I was not able to find).

Could you please help me with this issue, for it is stopping me know.

Thank you very much.

I also prepared a small project to illustrate this. Please take a look at “Main screen”. Thanks.

issue001.zip (287.4K)

Hi Darius,

The problem of refreshing the datasources can be easily fixed by invoking DsContext.resumeSuspended():


public class MenuScreen extends AbstractWindow {

    private VBoxLayout dataBox;

    @Inject
    private HierarchicalDatasource<Menu, UUID> menusDs;

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);

        dataBox = (VBoxLayout) params.get("dataBox");

        menusDs.addItemChangeListener(e -> {
            Menu item = e.getItem();
            if (item != null) {
                dataBox.removeAll();
                String screen = item.getScreen();
                if (screen != null) {
                    AbstractFrame frame = openFrame(dataBox, screen, null);
                    dataBox.expand(frame);
                    // add this
                    ((DsContextImplementation) frame.getDsContext()).resumeSuspended();
                }
            }
        });
    }
}
Please note also that using regular screens as frames is not recommended and can be broken in a future (major) platform release (see for example https://youtrack.cuba-platform.com/issue/PL-6913). So better create frames and use them in both regular browsers and your tree-based screen.

Hi Konstantin

Many thanks. I had some gut feeling, that this should be simple, but was not able to figure it out :slight_smile:
That one line fixed everything.