Help retrieving HTML parameters

Hi, I’m stuck with a problem that seems simple at first, so I’m sure you will give me the right answer :wink:

Here’s What I would like to do :
When I call my vaadin App, I 'd like to retrieve the parameters passed in the url (after the ?).
To do that I implement the ParameterHandler interface as seen in the book (see the code below : class IsisParameters)

The problem is that I wanted to use these parameters inside the init() method of my App (to check login issue with user name / passwd), and apparently, they are not yet initialize at this point…
For What I can see, the handleParameters method is invoked AFTER the init method.
Is that right ?
and In that case, at which moment I can try to read these parameters ?

Below you can find the class implementing the ParameterHandler in which I would like to store the parameters retrieved
And then the init method of my Main class (my application)

Thanks !

[font=Courier New]
package isis.common.vaadin;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

import com.vaadin.terminal.ParameterHandler;

/**

  • Classe servant à récupérer les paramètres envoyés à l’application…
  • @author fregnaut

*/
public class IsisParameters implements ParameterHandler {

private Hashtable params = new Hashtable();

public IsisParameters () {
}

public void handleParameters(Map parameters) {

	for (Iterator it = parameters.keySet().iterator();it.hasNext();) {
		String key   = (String) it.next();
		String value = ((String[]) parameters.get(key))[0]

;
params.put(key,value);
System.out.println("Key: “+key+”, value: "+value);
}

}

/**
 * Renvoie la liste complète des paramètres
 * @return
 */
public Map getParameters() {
	return params;
}

/**
 * Renvoie la valeur du parametre demandé, null sinon
 * @param paramName
 * @return
 */
public String getParameter (String paramName) {
	return (String) params.get(paramName);
}

}

[/font]

[font=Courier New]
public class Main extends Application {

private Window mainWindow;
private VerticalLayout mainLayout ;
private MainView mainView;

@Override
public void init() {

	mainWindow = new Window("Isis_vaadin_general_country Application");
	IsisParameters params = new IsisParameters();
	mainWindow.addParameterHandler(params); 

	// iF i TRY TO READ THE PARAMETERS AT THAT POINT / THEY ARE ALL NULL....
	System.out.println(params.getParameter("myParam"));

	buildMainLayout();
	initUi();
	declareEvents();

	setMainWindow(mainWindow);
	

}

[/font]

Hi,

You are right that init is invoked before the parameter handler and that is why you dont have any parameter values there yet. Sorry.

If your UI initialization depends on parameter values, you have to delay your UI initialization until the handleParameters is invoked.

By quickly looking your code I would say that it is easiest for you to move these:

buildMainLayout();
initUi();
declareEvents();

into
handleParameters
function (this might have some side effects, but they should be easy spot and fix)

PS. Welcome to the world of event-driven web applications :slight_smile:

Thanks, it worked.

What I did finally is that I made my Application class implements the HandleParameter method itself.
So it is easy then to call my other methods that draws the UI

Yes, that’s right. It is the easiest way.

You probably already noticed this, but just a tip to all others too: While your application get larger, you probably want to divide the UI initialization even further. Try inheriting
Window
or
CustomComponent
and create
logical UI elements
that are easier to maintain and reuse.