Session problem in Vaadin 7

I’m using Vaadin 7 session management mechanism. So, I’ve this class:


public class YeWebApp extends UI {
	@Override
	protected void init(VaadinRequest request) {
		// Authentication: check if user is found, otherwise send to login page
		UserSession userSession = (UserSession) YeWebApp.getUserSession();

		if (userSession == null) {
			VaadinSession.getCurrent().setAttribute("yeWebApp", this);
			getCurrentApp().setContent(new CssLayout());
			initBeans();
			initLogin();
		} else {
			CssLayout content = ((CssLayout) getCurrentApp().getContent());
			if (content != null) {
				content.removeAllComponents();
			}
			getCurrentApp().mainLayout.buildView();
			setContent(getCurrentApp().getContent());
		}
	}

And that’s working fine. But, if I refresh my Application with F5 or open a new tab and try to enter in a window using this method:


	public void showPopupWindow(PopupWindow window) {
		YeWebApp.getCurrentApp().getUI().addWindow(window);
	}

The Window just don’t show. It’s like my App have lost the UI reference or something like that, the code executes fine, but don’t display any window after the refresh.

What is wrong?

Regards,

Refreshing the browser window by default creates a new UI instance, so the one you stored in the session at login is not actually attached to the application anymore. You can make Vaadin reuse the UI by adding a @PreserveOnRefresh annotation to the UI class.


However
, your code assumes that there’s only one UI per user session - an assumption which will most likely break your application if the user ever opens another tab or browser window in the same session! If you need a “global” reference to the UI that’s
currently
being processed, use the static method UI.getCurrent() that returns a reference to a thread-local variable.