jsp - java.lang.RuntimeException Cannot find FacesContext -
i don't know how continue, "java.lang.runtimeexception: cannot find facescontext" new jsf 1.2 web application. i'm sure it's configuration can't find.
the exception occurs first f: or h: tag. important <f:view> @ beginning.
my index.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en"> <f:view> <html> <head> <title>mywebsite</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> </head> <body> <div>mycontent</div> </body> </html> </f:view> my web.xml looks this:
<?xml version="1.0" encoding="utf-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>faces servlet</servlet-name> <servlet-class>javax.faces.webapp.facesservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <context-param> <param-name>javax.faces.default_suffix</param-name> <param-value>.jsp</param-value> </context-param> <servlet-mapping> <servlet-name>faces servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <session-config> <session-timeout>720</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> and have faces-config.xml should reference mybean want use afterward in body of page:
<?xml version='1.0' encoding='utf-8'?> <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"> <application> <view-handler>com.sun.facelets.faceletviewhandler</view-handler> </application> <managed-bean> <managed-bean-name>myclassname</managed-bean-name> <managed-bean-class> com.company.classname </managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> </faces-config> what missing here?
java.lang.runtimeexception: cannot find facescontext
thus, jsf <f:xxx> , <h:xxx> tags complaining facescontext cannot found. facesservlet 1 responsible creating faces context. faces servlet invoked when request url matches url pattern, in particular case *.jsf. so, when open index.jsp http://localhost:8080/context/index.jsp, or relying on <welcome-file> setting, not invoking faces servlet , indeed exception.
you need open index.jsp http://localhost:8080/context/index.jsf, or set welcome file entry index.jsf in order invoke faces servlet, can create faces context required jsf components declared in jsp page.
note fixing welcome file isn't sufficient in jsf 1.x + tomcat environment. need supply physically existing, empty index.jsf file next index.jsp file in webcontent in order fool tomcat index.jsf exists welcome file. otherwise show 404 error because checks physical presence of welcome file beforehand.
see also:
unrelated concrete problem, i'm wondering why you're using jsp if you've apparently installed facelets 1.x , registered view handler. facelets far superior jsp.
Comments
Post a Comment