For this you should use Filter .
eg.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException { if (((HttpServletRequest) request).getSession().getAttribute("user") == null) { ((HttpServletResponse) response).sendRedirect("error.jsf");
Here, I assume that User is placed in the session area, as you usually expect. This may be a session-driven JSF bean named User .
The navigation rule does not apply, since there are no bean means during a normal GET request. In addition, performing a redirect when a managed bean should be constructed does not work gong, because when a managed bean needs to be constructed during a normal GET request, the response has already begun to display and that the point is without return (it would only IllegalStateException: response already committed ). PhaseListener is cumbersome and overwhelming since you actually don't need to listen to any of the JSF phases. You just want to listen for βsimpleβ HTTP requests and the presence of a specific object in the session area. For this, the filter is ideal.
source share