Short question: Is it possible to do a redirection, say when a user isn’t logged in, when a page is rendered?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For that you should use a
Filter.E.g.
Here I assume that the
Useris been placed in the session scope as you would normally expect. It can be a session scoped JSF managed bean with the nameuser.A navigation rule is not applicable as there’s no means of a “bean action” during a normal
GETrequest. Also doing a redirect when the managed bean is about to be constructed ain’t gong to work, because when a managed bean is to be constructed during a normalGETrequest, the response has already started to render and that’s a point of no return (it would only produceIllegalStateException: response already committed). A PhaseListener is cumbersome and overwhelming as you actually don’t need to listen on any of the JSF phases. You just want to listen on “plain” HTTP requests and the presence of a certain object in the session scope. For that a Filter is perfect.