A common problem with JSF applications is that the JSP or Facelets files that the Faces Servlet uses to render the pages are also accessible via the ‘normal’ web server process, bypassing the Faces Servlet. This can lead to unexpected errors, probably something like:
java.lang.RuntimeException: Cannot find FacesContext
This section presents a simple solution to this problem. A pretty straightforward solution is to implement a Filter
that redirects requests that go directly to the page. A simple Filter
implementation could look like this:
import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class RedirectFilter implements Filter { private final static String FACES_PREFIX...