All fine so far, but my action opens a Edit screen and I need the table to refresh after the EditScreen is closed. This sounds like a very standard easy task, right? But it was not (for me).
I needed a custom action because I want the function to be available in the right-click menu. So here are the challenges I faced.
Adding a afterCloseEvent to the edit screen would be the way to go I thought, but I cannot access the dataContainer, nor the dataLoader from my custom Action
The method target.getDatasource() is deprecated
I cannot access target in my afterCloseEvent
the method refreshState() from ListAction doesn’t refresh my dataContainer. Not sure what it refreshes.
My workaround / complex solution:
I created a new UiEvent class
I published the event in the afterCloseEvent of the custom action
I listen to the new UiEvent in the ViewController that contains my treeTable component
When event occurs I do myeasyDl.load();
There must be an easier way to do this… Please help.
Perhaps your action is a subclass of ListAction, so its getTarget() method returns a ListComponent like Table or DataGrid. Then you can obtain the CollectionContainer linked to this ListComponent as it is done for the standard edit action, see cuba/EditorBuilderProcessor.java at master · cuba-platform/cuba · GitHub
Thanks @krivopustov, I do however think that my “complex” solution is actually easier than the solution you suggest.
However, it would be even better if there was already event listener attached to the dataContainer or the dataLoader which I would then just publish?
Here is the code from my custom Action that extends ListAction
@Override
public void actionPerform(Component component) {
OU parentOU = (OU) getTarget().getSingleSelected();
OU newOu = new OU();
newOu.setParent(parentOU);
Screens screens = ComponentsHelper.getScreenContext(target).getScreens();
OUEdit screen = screens.create(OUEdit.class);
screen.setEntityToEdit(newOu);
screen.addAfterCloseListener(afterCloseEvent -> {
OuAddedEvent event = new OuAddedEvent(this);
events.publish(event);
});
screens.show(screen);
}