Refresh UI screen after REST api enity instances database Update

Hi Everyone,

This post is information for refreshing the view after database update/create of composition entities.

I have a master entity editor screen and some of its attributes which are composition atrributes are updated by external REST API call. How can i refresh the view of master entity editor screen with the updated attributes.

Using EntityListeners i can get events only to middleware, how can i get the event for database changes to UI layer.

Thanks in advance for the help/

Hi,

You can check out the global events addon, which will cover your case: Global Events – CUBA Platform

More information about events in general can be found in this guide: https://cuba-platform.com/guides/decouple-business-logic-with-app-events

Bye
Mario

1 Like

Hi Mario,

Thanks for the reply.
I added global event custom component into the project and registered for entitychangeevent for the entity. Once the entitychange listener is invoked i am sending global UI event. In the screen controller i have registered a listener for the event. But i am receiving the event in the UI.

Below is my code:

Entitychange listener –

@EventListener
public void beforeCommit(EntityChangedEvent<Submission, Long> event) {
    Id<Submission, Long> entityId = event.getEntityId();
    EntityChangedEvent.Type changeType = event.getType();

    AttributeChanges changes = event.getChanges();
    System.out.println("before commit event"+changes.getAttributes().iterator().next().toString());
    String message = "Received commit changes from middle layer";
    events.publish(new UiNotificationEvent(this, Strings.isNullOrEmpty(message) ? "test" : message));
}

UInotification event listener

@EventListener
public void onUiNotificationEvent(UiNotificationEvent event) {
    System.out.println("Received {}"+ event.getMessage());
    if(submissionDc.getItem() != null) {
        dataManager.reload(submissionDc.getItem(), "submission-view");
    }else{
        System.out.println("current item is null in uinotification event");
    }
}

I dont see any error logs in the studio
Please help me in resolving the issue.

I was able to resolve my issue.
Thanks Everyone