PrettyFaces implements URL rewriting by intercepting incoming requests in a Servlet filter and then forwarding it to the real URL.
The DispatchType
of a filter configures for which kind of request the filter should be applied. The default is REQUEST
which is the usual case. If you set it to FORWARD
it is only applied to requests that are internally forwarded (which is what PrettyFaces does).
In case of REQUEST
you are getting the NPE because your filter executes before the PrettyFaces filter and so you cannot access the PrettyContext
.
It is absolutely fine for you to use FORWARD
in your case. The only thing that you have to remember is that HttpServletRequest.getRequestURI()
will return the real URL instead of the pretty one for forwarded requests.
Your back button problem is probably related to caching. If you don't set correct caching heads, the browser will cache the last page and so pressing BACK will simply redisplay the last page without sending a request to the server.