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?
I think there are two options, but I haven’t checked them yet.
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.
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: