The correct way to use Window management feature?

Hello,

I faced problems when I tried to use the windows management feature (the safe way to open multiple browser windows of the same application without synchronization errors; see #1970) of the toolkit with the new 5.2.12 version of the jar. With the new jar my application is initialized 3-6 times when it is opened in the browser.

I wonder wheter I use the feature wrong way or is the 5.2.12 broken?

Relevant parts of my application are shown below:


public class TestApplication extends Application {
   Label l = new Label("Hello");
public Window getWindow(String name) {
		// If we already have the requested window, use it
		Window w = super.getWindow(name);
		if (w == null) {
			// If no window found, create it
			w = createNewWindow(name);
		}
		return w;
	}

	public Window createNewWindow(String name) {
		Window window = new Window(name);
		this.addWindow(window);
		this.init(window);
		return window;
	}

	public void init() {
		Window win = new Window();
		this.setMainWindow(win);
		init(win);
	}

	public void init(Window mainWindow) {
		System.out.println("init");
		mainWindow.setSizeFull();
		mainWindow.addComponent(l);
        }
}

This feature is rather critical to my customer project… It would be nice if someone could tell me the correct way to use this feature!

Finally found some time to look at this, sorry for the delay.

Could you explain a little more what you mean - is Application.init() called 3-6 times when you first browse to the application? Or your init(Window)? Or is this happening when you open a second window, in addition to the main window?

Thank you, for your reply. Here is what happens when I open the application in the empty FF3 window first time after the Tomcat has been started:

app init
my init
get window
create new window
my init
get window
create new window
my init
get window
create new window
my init
get window
get window
create new window
my init
get window
create new window
my init

The problem seem to be that the getWindow-method could not find the correct window and thus creates a new multiple times. The implementation of getWindow()-method is directly from the example in the javadoc of Application.getWindow().

There could be also problems in my implementation of createNewWindow-method…

Hmm. I think I found the solution for this: in the application init-method one have to explicitly set the name for the first main window:


public void init() {
   System.out.println("app init");
   Window win = new Window();
   win.setName("TestApplication");
   this.setMainWindow(win);
   init(win);
}

Otherwise, name will be generated from random numbers (e.g. ‘234578’). Afterwards, when the application asks for the main window with the name of the application (‘TestApplication’) it is not found and thus a new window is created.

Ok, I got my TestApplication working but now I have more complicated problems with the real application of my customer project:

The app is inited correctly and the layout seem to be ok. But, after the layout is drawn in the browser window the “Session expired”-pop up notification is shown and it continues to pop-up after clicking it :frowning:

When debugging the app in the eclipse I noticed that there is two threds (http-8080-1 and http-8080-2). The first thread initializes the app and do the layouting, but then it seems that the second threads try to do it again and soon after that it causes “com.itmill.toolkit.terminal.gwt.server.CommunicationManager$InvalidUIDLSecurityKeyException: Security key mismatch” exception in the ApplicationServlet and thus the session is invalidated!

Problem solved. I was forgotted to recompile one of the custom gwt-components… :expressionless: