java.lang.RuntimeException Cannot find FacesContext

java.lang.RuntimeException: Cannot find FacesContext

Thus, the JSF <f:xxx> and <h:xxx> tags are complaining that FacesContext cannot be found. The FacesServlet is the one responsible for creating the faces context. The faces servlet is invoked when the request URL matches its URL pattern, which is in your particular case *.jsf. So, when you open the index.jsp as http://localhost:8080/context/index.jsp, or are relying on the <welcome-file> setting, then you are not invoking the faces servlet and you would indeed get this exception.

You need to open the index.jsp as http://localhost:8080/context/index.jsf, or to set the welcome file entry to index.jsf in order to properly invoke the faces servlet, so that it can create the faces context which is required by the JSF components declared in the JSP page.

Note however that only fixing the welcome file isn’t sufficient in this JSF 1.x + Tomcat environment. You also need to supply a physically existing, but completely empty index.jsf file next to the index.jsp file in the webcontent in order to fool Tomcat that index.jsf really exists as welcome file. It would otherwise show a 404 error because it checks the physical presence of the welcome file beforehand.

See also:


Unrelated to the concrete problem, I’m wondering why you’re using JSP if you’ve apparently installed Facelets 1.x and registered its view handler. Facelets is far superior to JSP.

Leave a Comment