Hi, I’m stuck with a problem that seems simple at first, so I’m sure you will give me the right answer
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]