Vaadin login examples

Have problem with making login on vaadin framework. I still could not get how realize on vaadim such thing as redirection on another page, when person insert correct password and nickname. It will be great if after login data validation vaadin reload or overwrite main window to new window.


	@Override
	public void init() {
		final Window loginWindow = new Window("Please login");
		setMainWindow(loginWindow);

		AbsoluteLayout layout = new AbsoluteLayout();
		layout.setSizeFull();
		loginWindow.setContent(layout);

		LoginBox loginBox = new LoginBox(loginWindow);
		loginBox.addListener(new LoginBoxListener() {
			@Override
			public void componentEvent(Event event) {
				Authentication auth = SecurityContextHolder.getContext().getAuthentication();
				if (auth != null) {
                     // main window is will be show only after page reload
					setMainWindow(new SeabankWindow());
				} else {
					loginWindow.showNotification("Authorization failed. Please check input data.",
							Window.Notification.TYPE_ERROR_MESSAGE);
				}
			}
		});
		layout.addComponent(loginBox, "left: 35%; top: 30%");
	}

The code is probably correct, but if I remember correctly there’s a bug in the Vaadin framework when changing the main window of the application. The window change takes place only after reload, like you desribed.

The workaround is to change the main layout for the main window instead of the whole window, i.e.
mainWindow.setContent(new SeabankWindowContent());

Ajax applications do not reload pages, just modify the current page. So, you don’t redirect after login, but (for example) replace the layout of the main window with setContent().

One handy pattern for doing this is to use a view or screen manager that allows switching between login/main/help/etc screens. See
GasDiaryApplication.java
,
ViewManager.java
, and
LoginScreen.java
for examples. The
AppFoundation
add-on implements one such view manager and might also be otherwise useful.

Thanks a lot for your help. Very nice examples.:slight_smile: