Is there something like an eventbus in vaadin. For most of the events, an instance of a event needs to created and passed on as an argument making the owner a listener for multiple events through different methods. Rather than that, is it possible to have a single method listen for multiple events through annotations?
It depends on what events you are talking about , the component events dont have an event bus .
If you are talking about your own custom event you could use CDI events, even with CDI Events a single method cannot observer multiple event types though…
The second option is to use JMS.
there’s no eventbus-like mechanism in vaadin, but there is an event router (see com.vaadin.event.EventRouter and package.html in com.vaadin.event). This is used for internal vaadin event handling, so surely it could have some limitations. Unfortunately I can’t tell you more about this since I have not actually used it for external purposes.
Import EventBusConfiguration.class into your Spring configuration (may not be required if Spring Boot is used with @EnableAutoConfiguration)
Wire in appropriate event bus (check doumentations for different types available), here I am using one that works per UI instance: @Autowired
private EventBus.UIEventBus uiEventBus;
Publish event as required, eg:
uiEventBus.publish(this, new RefreshMainViewEvent(this, “Usage details updated”));
Subscribe to event in the other component class @PostConstruct
public void afterPropertiesSet() {
uiEventBus.subscribe(this, false);
}
Add the action to be done on event (in the same class here) : @EventBusListenerMethod
public void closeSymmUsageWindow(RefreshMainViewEvent event) {
logger.debug(“Received {}”, event);
//blah
}