Get Fragments-Instance in Mixins

Hello,

I would like to write a mixin which, under certain conditions, adds a fragment to the screen.

Source Code:

@Subscribe
default void initBanner(Screen.BeforeShowEvent event) {
    BeanLocator beanLocator = Extensions.getBeanLocator(event.getSource());
    UiComponents uiComponents = beanLocator.get(UiComponents.class);
    Fragments fragments = beanLocator.get(Fragments.class);
    ...
}

Unfortunately I get the message “NoSuchBeanDefinitionException: No qualifying bean of type ‘com.haulmont.cuba.gui.Fragments’ available”.

What do I have to do to get an instance, or is there an alternative way to add fragments through a mixin?

Thanks and best regards
Andreas

Hello @Andreas.Brueck

Fragments is not a bean in general sense, it is injected via our inner mechanisms, not with Spring.

You should either inject in into controller with @Inject annotation, or use UiControllerUtils class like this:

UiControllerUtils.getScreenContext(frameOwner).getFragments()

Regards,
Daniil

1 Like

Hello Daniil,

works great, thank you. :grinning:

Andreas