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… 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”?