[Flow UI] Interact with central component from views

Hi there,

I have the following scenario where I’m not 100% on how to handle it in Jmix 2.x Flow UI.

I’m currently opening an Intercom widget in the Main View with the help of a custom Lit component.

What I now would like to achieve is in some views to notifiy the intercom widget to do particular things (like create a new message based on a button click or something).

Since the instance of the IntercomWidget is registered in the MainView, I’m not sure how I can get a handle on it. I was also thinking about an UI event approach, as it has been possible in CUBA / Jmix 1.x).

Can you provide some ideas on how to interact with this central “instance” of a widget?

Cheers
Mario

Hello Mario!

I think there are two options, but I haven’t checked them yet.

  1. Global events as you mentioned. You can listen global events in views like it was in Jmix 1x. Firstly you should add @com.vaadin.flow.component.page.Push annotation to class that implements AppShellConfigurator, usually it is a main Spring Boot application class.

    Then you can send and listen Spring Application events in views:

    @EventListener
    public void myUiEventHandler(MyUiEvent event) {
        // handle event
    }
    

    To send event see UiEventPublisher.

  2. Second option is trying to find element in client-side and invoke some function of the component (if it still in the page). For instance:

    UI ui = UI.getCurrent();
    ui.getElement().executeJs("document.getElementsByTagName('myIntercom')[0].showNotification($0);", "Some message");
    

Hi @pinyazhin,

thanks for the hint. The event publisher approach worked out well :+1: