Vaadin 7 Navigator Logout Conundrum

Ok – So I’m obviously confused as to how the new Navigator / View stuff works and the new lifecycle of a V7 app. :slight_smile:

Here is what I want to do, a pretty standard pattern I would think. Have 2 views – a “Login” view and then a “Main” view that is the basic application. I have the 2 views and I think everything is going ok there … this uses the V7 Tutorial on Navigator/login etc.

The issue is the logout part … I have a menu option for a logout. What I want to happen is to clean up all current resources and “restart” the – well – that’s the question – restart everything just as if they come to the URI the first time. WIth a clean session, UI, etc.

I’ve tried all sorts of combinations of navigating back to the LoginView then closing the UI (UI.close()) and/or closing the session (getSession().close()) …

But everything has issues… either I get some nasty stack traces – errors/warning about resources not being released – No UI provider for the request or whatever…

I’ve tried just about every combination I could think of – and nothing is right.

How do I implement a “clean” Logout from within the MainView – that “starts over” again with a new session/UI etc. and the LoginView ?

Thanks!

Well of course, within minutes of posting the question - I tried a NEW combination and now it behaves as I had hoped.

However, I am still getting some warning messages that disturb me:

Feb 07, 2013 9:20:13 AM com.vaadin.ui.ConnectorTracker unregisterConnector
WARNING: Tried to unregister HorizontalLayout (41) which is not registered
Feb 07, 2013 9:20:13 AM com.vaadin.ui.ConnectorTracker unregisterConnector
WARNING: Tried to unregister StatusBar (42) which is not registered

My solution was to do the following btw in my Logoff code …

	private Command	logoutMenuCommand	= new Command() {
											public void menuSelected( MenuItem selectedItem )
											{
												// For a logout -- we simply need to reset our logged in user and then navigate back to the login page 
												logger.trace( "User clicked Logout menu item" );
												( (OMSOnlineUI) UI.getCurrent() ).setLoggedInUser( null );
												getUI().getPage().setLocation( "/" );

												logger.trace( "VaadinSession.close() called" );
												getSession().close();

											}
										};

So I basically set the Location back to “/” (the root of the application) and the call session close … and viola – the UI and everything appears to be restarting itself again nice and cleanly…

I’m going on a tangent on the topic. You actually found the right way to get a new session in vaadin - close it and redirect to start. What I would like to comment is that I would take a little bit of different approach regarding the log-in screen. I would leave that outside of the navigator. You would first show a layout with the log-in fields, and upon a successful log-in, you switch the content to the main application layout which initializes the navigator and all that. This way the application doesn’t know anything about the other views before you have logged in and you don’t have to take care of special cases where user types in the name of a view in the url before they have logged in and gained access there.

Just my thoughts on the matter, and take them as just thoughts :slight_smile:

PS. If you want to take it one step further, the log-in page could be totally outside the Vaadin app as a separate HTML page. This allows the browser to store the login credentials, as well as have faster load-up times of the log-in page as it doesn’t have to load up the Vaadin widgetset and theme.

Jens –

Thanks for the response –

I think you are exactly right on how a better login approach should work – i.e. not have it as part of Navigator system at all, since it really doesn’t add any value.

However, I do plan to keep the LoginView (as it were) as part of the overall Vaadin app because it needs to do quite a few things (like check the login credentials and keep various security ACL information around for the rest of the app, etc). Besides, I hope that 95+% of the time if a user hits the login screen, they will successful login – so the small start up time for the login screen (for this app anyway) in minimal … Of course, that’s my use case and other’s may have different use cases.

Cheers!

Exactly. That was why I put that part under the “Ps.” section. It’s a bit of a niche section which most have no need to, but still relevant to some.

can you please post a sample application of the approach that you described here
“I would leave that outside of the navigator. You would first show a layout with the log-in fields, and upon a successful log-in, you switch the content to the main application layout which initializes the navigator and all that” in the above statement. I believe this is the cool approach i was thinking about.

Dear Jen can please post a sample