Handling page redirection using preRenderView
I'm having trouble understanding what is happening with a page redirection I am trying to perform. I'm using JSF 2.0.3-SNAPSHOT (waiting for 2.0.3 release).
I have at the top of my page the following snippet:
The code for this method is the following (the relevant part anyway):
FacesContext fc = FacesContext.getCurrentInstance();
NavigationHandler navigator = fc.getApplication().getNavigationHandler();
String page = "welcome?faces-redirect=true";
navigator.handleNavigation(fc, null, page);
When I run this code, I find that this method gets called twice (which is odd) and on the 2nd time through I get a java.lang.IllegalStateException.
However if I change the page to simply "welcome", everything works perfectly except that the URL displayed in the browser is the original page (which is what I am trying to avoid).
Am I handling the navigation correctly?
Is there something I should be doing differently? I don't fully understand why the "faces-redirect" causes an error that the other case doesn't.
Is there a better way of handling this type of case (I'm trying to protect certain pages depending on whether is logged in or not).
Any ideas would be much appreciated!