What I am trying to do is to be able to pass a parameter through an URL and execute certain actions if this parameter is being passed or not. I am using JSF + Richfaces.
For example if I try to access http:// localhost/myapp/home.jsf
public class My Bean {
private boolean printHello = false;
public MyBean(){
FacesContext fc = FacesContext.getCurrentInstance();
String printHello = fc.getExternalContext().getRequestParameterMap().get("printHello");
if (printHello != null && printHello.equals("true")
printHello = true;
}
public void myFunction() {
if (printHello)
System.out.println("test");
//other stuff
//ask for some user input
}
//When user validate his input, this function is called
public void myFunction2() {
//some stuff
}
}
When I am asking for the user input in myFunction(), I also have a link on my page to start over the all process. If after clicking that link, and then manually change the url to http:// localhost/myapp/home.jsf?printHello=true
The bean won't be cleared and my printHello flag will still be set to false.
Also, when the following will be executed again:
FacesContext fc = FacesContext.getCurrentInstance();
String printHello = fc.getExternalContext().getRequestParameterMap().get("printHello");
printHello will be null, thats what I dont get. Maybe its due to the fact that not the all page is re-rendered?