Hello we have a Host screen class where we are creating our fragments.
We put the fragments in a HashMap and then we are loading a comboBox with the HashMap.
We use the comboBox to switch between the fragments. What we would like to achieve is subscribing for an event from the Host screen,
so we can visualize a warning on it. The event should be triggered from any of the fragments related to the Host screen.
What would be the best way to achieve this?
We have tried followingListening to Fragment Events in Host Screen, but we are getting the below error upon opening the HostScreen.
java.lang.UnsupportedOperationException: Unsupported @Subscribe target CONTROLLER. It is not a Fragment. at io.jmix.ui.sys.UiControllerDependencyInjector.initSubscribeListeners(UiControllerDependencyInjector.java:317)
In our application besides that we are loading the fragments programmatically, we are using Map to load the fragments and ComboBox for switching between them.
If you add fragments programmatically then the following listener can’t work because when the screen is initialized there is no fragment with the newFragment id on the screen:
Instead of declaring the listener using the method with the @Subscribe annotation you may explicitly add listener to the fragment when the fragment is created and added to the screen: