EventBus for Vaadin

Hi All,

    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?

Larsen.

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.

http://docs.jboss.org/cdi/spec/1.0/html/events.html

Hi,

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.

What you could look at are external solutions like CDI events or the BlackBoard add-on (
http://vaadin.com/directory/#addon/blackboard:vaadin
).

Hi Teppo,

     Blackboard really solved my problem. Thanks for the suggestion.

Larsen.

Google Guava library has an excelent EventBus class. I use it with my Vaadin project.

Vaadin addons has a nice Event Bus implementation. Check https://github.com/peholmst/vaadin4spring/tree/master/samples/eventbus-sample

I have done this using a spring enabled (NOT spring boot) Vaadin application, but it might work without Spring as well I guess, Short steps:

  1. Add the following dependency

    org.vaadin.spring.addons
    vaadin-spring-addon-eventbus
    0.0.7.RELEASE

  2. Import EventBusConfiguration.class into your Spring configuration (may not be required if Spring Boot is used with @EnableAutoConfiguration)

  3. 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;

  4. Publish event as required, eg:
    uiEventBus.publish(this, new RefreshMainViewEvent(this, “Usage details updated”));

  5. Subscribe to event in the other component class
    @PostConstruct
    public void afterPropertiesSet() {
    uiEventBus.subscribe(this, false);
    }

  6. Add the action to be done on event (in the same class here) :
    @EventBusListenerMethod
    public void closeSymmUsageWindow(RefreshMainViewEvent event) {
    logger.debug(“Received {}”, event);
    //blah
    }