How to update Browse screen after closing Edit screen when extending platform entity like Group

Hi there,

My project extends platform entity Group by adding one attribute “numberOfUsers”, and the dataSource groupsDs has the following query:

select g from sec$Group g order by g.numberOfUsers DESC

The ExtGroup is a “tree” component in xml:

 
<vbox id="topBox">
	<tree id="groupsTree"
		  height="100%">
	</tree>
</vbox>

When open ExtGroup browse screen the first time, all entries in the tree are displayed correctly. But when create a new group by clicking menu “Create->New”, fill in elements on Edit screen and return to Browse screen, the newly created group is NOT at the expected position of “order by g.numberOfUsers DESC” (I assume the ordering applies to all children group entries). My questions are:

  1. How to update ExtGroup Browse screen to reflect “order by g.numberOfUsers DESC” when Edit screen is closed?

  2. Why groupsDs is NOT available in ExtGroup Browse controller (It is NOT in the list when using Alt+Inject). Is there any way to access groupsDs and get the list of entries from it?

I found on forum this thread looks similar, but I still can not figure out the problem I am facing:
https://www.cuba-platform.com/discuss/t/how-to-refresh-browse-datasource-after-closing-edit-screen

Thanks,
-Mike

Hi Mike,

Let me quickly answer your second question, and having the datasource you should be able to refresh it when needed.

You certainly can inject the datasource into your controller, just do it manually, by specifying a variable of appropriate type and name and annotating it with @Inject. Probably the IDEA plugin that shows you possible injection options just cannot read the components and datasources from the base screen.

Or even better: the base screen GroupBrowser already contains the needed field with protected access:

@Inject
protected HierarchicalDatasource<Group, UUID> groupsDs;

So you can just use it in your controller without redefinition.

Hi Konstantin,

I am making progress following your instructions. Thank you.

The groupsDs is injected. The CreateAction and its action handler are created (please see the attached file).

However, when I click the “Ext Groups” menu, this error occurs:

"GuiDevelopmentException: Can’t find action ‘export’ in ‘groupsTree’

Frame ID: sec$Group.browse
XML descriptor: cloud/pospro/posportal/gui/extgroup/ext-group-browse.xml
Holder ID: groupsTree"

What I am missing here?

-Mike

ext-group-browse-createAction.txt (1.7K)

Hi Mike,

First of all remove everything unneded from the XML descriptor. In the simplest case when you don’t want to add any visual components, it can be almost empty:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        class="com.company.sample.web.screens.ExtGroupBrowser"
        extends="/com/haulmont/cuba/gui/app/security/group/browse/group-browse.xml"
        messagesPack="com.company.sample.web.screens">
    <layout>
    </layout>
</window>

Second, due to Group controller initializes actions programmatically, obtain the action directly from the Tree component as follows:

package com.company.sample.web.screens;

import com.haulmont.cuba.gui.app.security.group.browse.GroupBrowser;
import com.haulmont.cuba.gui.components.actions.CreateAction;

import java.util.Map;

public class ExtGroupBrowser extends GroupBrowser {

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);
        CreateAction createAction = (CreateAction) groupsTree.getActionNN("create");
        createAction.setAfterCommitHandler(entity -> {
            groupsDs.refresh();
        });
    }
}

After these modifications I have managed to extend the group browser and to make it refresh the tree as needed.

Works like a charm, Konstantin!

Thank you very much,
-Mike