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.

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

		AbsoluteLayout layout = new AbsoluteLayout();

		LoginBox loginBox = new LoginBox(loginWindow);
		loginBox.addListener(new LoginBoxListener() {
			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.",
		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
, and
for examples. The
add-on implements one such view manager and might also be otherwise useful.

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