LOGOUT

I’m using Vaadin 7 and the Navigator.
My first page (i.e. “/”) is a login page.
My app also has a logout button,which, following https://vaadin.com/wiki/-/wiki/Main/Handling+logout: attempts to close the session and redisplay the login page:

VaadinSession.getCurrent().close();
getUI().getPage().setLocation(contextRoot + "/");

The result is:

com.vaadin.server.ServiceException: java.lang.IllegalStateException: This UI instance is already initialized (as UI id 0) and can therefore not be initialized again (as UI id 0). Please make sure you are not accidentally reusing an old UI instance.

Can anyone explain what is going on? It seems like I also need to “invalidate” the UI as well.
How can I do this? I tried calling getUI().close(), but the same exception resulted.

I’m using the following code to logout.

    /**
     * Exit application
     */
    public static void exit() {
        UI.getCurrent().close();
        VaadinSession.getCurrent().close();
        Page page = Page.getCurrent();
        String location = StringUtils
            .substringBeforeLast(page.getLocation().toString(), page.getUriFragment());
        location = StringUtils.substringAfterLast(location, "#");
        page.setLocation(location); 
        
    }

Hmm… that doesn’t work for me either… I’m still getting the same exception:

java.lang.IllegalStateException: This UI instance is already initialized (as UI id 0) and can therefore not be initialized again (as UI id 0). Please make sure you are not accidentally reusing an old UI instance.

Are you using the default UIProvider?

I’m currently using the CDIUIProvider… but I was getting the same error when using the default UI provider.

I just added this to my logout message, and it seems to have solved the problem (more testing needed though!):

VaadinService.getCurrentRequest().getWrappedSession().invalidate();

Seems like something was still being retrieved from the HttpSession…

I meant “method”, not “message” :slight_smile: