VaadinServlet : how to get main UI reference

Dear Vaadin community,

In my vaadin7 application, the 2 main classes are :

  • StartingClass extends UI
  • MyServlet extends VaadinServlet (for doing stuff for each incoming request)

In order to use the same log file for these 2 classes, i need to get the StartingClass reference into MyServlet, do you know how to do it ?

I tried to use the following code but it doesn’t work :

ArrayList<UI> collUi = (ArrayList<UI>) VaadinSession.getCurrent().getUIs();
for (Iterator<UI> it = ((Collection<UI>)collUi).iterator();it.hasNext();)
    if (it instanceof StartingClass ) {
        StartingClass ref_startingClass = (StartingClass ) it;


I didn’t try it myself yet but did you already try using UI.getCurrent() ?

I tried to use your solution (UI.getCurrent() ), but the result is still empty.
Maybe it is because the onRequestStart() method from “MyServlet extends VaadinServlet” is executed before the initialisation of the first UI ?

This point was better with Vaadin 6 because all was in the same class !


So, no other idea about my problem ?


I think you’re doing things the wrong way around. There can be multiple StartingClass instances per session - one for each open browser tab, and in addition there may be closed ones that are not yet cleaned up. (For example, refreshing the browser window will create a new UI instance by default.) You should instead access the servlet in StartingClass - for instance calling VaadinServlet.getCurrent().

Ok. In fact, i would like to integrate a WIndows SSO (Single Sign On) like Waffle, inside my Vaadin7 application.
I created another thead => “Vaadin7: How to integrate a “Single Sign On” like Waffle ?”