How to wait ... :-)

Please look at the code bellow.

I create a main window and start a login window in modal mode.
The login window is shown accordantly but this part is also executed

ITKerrorlog p = new ITKerrorlog(“Errors”, dbProps, mainWindow);
mainWindow.addComponent(p);

It would be nice if the main application wait on a result of my login window.
How can I do that?

Chris

public void init() {

    mainWindow = new Window();
	setMainWindow(mainWindow);
	
	usr = new user();
	
	String basedir = this.getContext().getBaseDirectory() + "/WEB-INF/";
    Properties dbProps = new Properties();
	    try {
	    	dbProps = new Properties();
			dbProps.load(new FileInputStream(basedir + "itk.properties"));
	    }
        catch (Exception e) {
            System.err.println("Can't read the itk.properties file. " +
            				   "Make sure itk.properties is in the CLASSPATH");
	            return;
	    }
	    		    
		l = new ITKLoggon("Login", dbProps, mainWindow);
		l.setModal(true);
		l.center();
		l.setClosable(false);
		l.setCaption("ITK login");
		mainWindow.addWindow(l);
	    	    
	    try {
	    	ITKerrorlog p = new ITKerrorlog("Errors",  dbProps, mainWindow);
	    	mainWindow.addComponent(p);	
	    }
        catch (Exception e) {
            System.err.println("cannot start main app");
	        
            return;
	    }		    

}

The short answer is: you cannot. You cannot block the server side thread handling UI updates. No UI updates (including the login click etc.) are received from an application instance while processing a request from that application. The same thread is also reused by the server (e.g. Tomcat) to receive requests also from other users in a multi-user application etc.

This is a general issue with event driven UIs or applications and is not specific to Vaadin.

Instead, you need to listen to events from the login window and react to it by doing any further processing.

If you are not used to this way of thinking about UI development, this might feel clumsy but is something you need to get used to. After a while, you will also design slightly differently and not try to make the application execution one big linear process.

Thanks for the answer.

I already fixed the problem.

My main application first starts the LOGIN form.
The Login button on the login window will doe the load of the rest of the application.

Simple but effective.

Chris