CDI - component - click listener doesn't fired

Hello,

I would like to use some CDI component in my application. I have created a “DesktopJumperComponent”. (Click than goes to the start, desktop view.) This is a layout, but it acts like a button. It comes from my previous base application which uses Vaadin 7.
So my new idea is that this component may be a CDI component. I inject it in MyUI, if logged in it’s visible, if not it’s not visible. Simple. It works. But. There is a layout click listener, which never fired… :frowning: Why?

Here is the code:

@SessionScoped
public class DesktopJumperComponent extends HorizontalLayout {

    @Inject
    private UserData userData;

    @Inject
    private EventBusHandler eventBus;
    
    public DesktopJumperComponent() {
    }

    @PostConstruct
    public void construct() {
        Button pictureButton = new Button();
        pictureButton.setStyleName(ValoTheme.BUTTON_LINK);
        pictureButton.setIcon(VaadinIcons.HOME);
        pictureButton.setCaption(null);

        setSpacing(false);
        addComponents(pictureButton);
        addStyleName("v-button v-widget slimhelpbutton");

        addLayoutClickListener((LayoutEvents.LayoutClickEvent event) -> {
            System.err.println("HomeJumperComponent: FIRED!!!!");
//            AppDefaultUI.getCurrent().getNavigator().navigateTo(StartPresenter.VIEWNAME);
        });

        setVisible(false);
        this.eventBus.register(this);
    }

    @Override
    public void attach() {
        if (!userData.isLoggedIn()) {
            setVisible(false);
            return;
        }
        setVisible(true);
    }
    
    @Override
    public void detach() {
        super.detach();
        this.eventBus.unregister(this);
    }
    
    @Subscribe
    public void handleLoggedInEvent(LoggedInEvent event) {
        setVisible(true);
    }

    @Subscribe
    public void handleLoggedOutEvent(LoggedOutEvent event) {
        setVisible(false);
    }
    
}

Did I miss something?
Or it’s not a good idea to take this component to a CDI “mode”?

I wonder, could it be that your Button is capturing the click event and thus you’re not getting to the layout click listener? Can you try without the Button?

-Olli

Hello Olli,

Thank you the good idea. I have tried. Same. Nothing happend. :frowning:
I have tried to add click listener to the picture button, but doesn’t work neither. :frowning:

I missed something…

If you just create that object normally with
new DesktopJumperComponent()
(and call construct() manually), does it work then?

-Olli

No, it doesn’t work. :frowning:
Thank you for help, Olli. The project doesn’t wait. :frowning: I have to move. So I have pass around the problem: I have use two menubar components: one for menu, and an other for user info and help button (on the up right corner of the screen). It’s good and simple and looks better than my previous solution.

Aww, that’s too bad :frowning:

Sounds like the issue is somewhere else than the CDI part, then. Good thing you found a workaround, at least.

-Olli