How to refresh dataloaders for new entities on windowcommit

I have a windowcommit handler that reloads some of the ui because i have dynamic settings there.

    @Subscribe
    public void onAfterInit(AfterInitEvent event) {
        addAfterCommitChangesListener(e -> reloadUi());
    }

    public void reloadUi() {
        getScreenData().loadAll();
        setEditable(invoiceService.canEdit(getEditedEntity()));
    }

I have a save button and the listener is correctly called. If I do this for an already existing entity everything works.

For newly created entities the getScreenData().loadAll() just keeps the in memory object, it doesnt go to the db to get the latest version. Should I do something special the first time the object is actually going to be persisted to associate it with the dataloader?

regards,
Tom

Hi Tom,

Indeed the loader does nothing after saving a new entity because it has no entity id assigned. The following should work:

@Inject
private InstanceLoader<Foo> fooDl;

public void reloadUi() {
    fooDl.setEntityId(getEditedEntity().getId());
    getScreenData().loadAll();

Perhaps this should be done by the framework. Created issue: Set InstanceLoader.id in StandardEditor after saving new entity · Issue #3153 · cuba-platform/cuba · GitHub

Regards,
Konstantin

1 Like