I\'m trying to code a simple JSF web application with a login system using Tomcat 7.
I have got two pages: index.xhtml and /restricted/welcome.xhtml.
Pages b
The FORWARD
dispatcher is only triggered when RequestDispatcher#forward() is been invoked somewhere in the webapp's code. The standard JSF navigation handler doesn't do that. It just invokes ViewHandler#createView() and sets it as current view by FacesContext#setViewRoot().
Send a redirect instead:
public String proceed() {
user.setLoggedIn(true);
return "restricted/welcome.xhtml?faces-redirect=true";
}
This is by the way also the recommended practice. Now it's a bookmarkable page (the URL change is now reflected in browser's address bar) and refreshing/F5'ing the page won't result in the POST unnecessarily being re-executed and pressing back button won't result in surprises.
If you really insist in invoking the FORWARD
dispatcher using JSF, you can always use ExternalContext#dispatch() method, but this is not the recommended way.
public void proceed() throws IOException {
user.setLoggedIn(true);
FacesContext.getCurrentInstance().getExternalContext().dispatch("restricted/welcome.xhtml")
}