Docs

Documentation versions (currently viewingVaadin 14)
You are viewing documentation for an older Vaadin version. View latest documentation

Session and UI Listeners

A SessionInitListener can be used to receive an event each time a new VaadinSession is initialized. Similarly, a UIInitListener can be used to receive an event each time a new UI is instantiated.

The ideal place to add both SessionInitListener and UIInitListener is inside a VaadinServiceInitListener.

public class ServiceListener implements VaadinServiceInitListener {

    @Override
    public void serviceInit(ServiceInitEvent event) {

        event.getSource().addSessionInitListener(
                initEvent -> LoggerFactory.getLogger(getClass())
                        .info("A new Session has been initialized!"));

        event.getSource().addUIInitListener(
                initEvent -> LoggerFactory.getLogger(getClass())
                        .info("A new UI has been initialized!"));
    }
}