• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problem JSF as RuntimeException: Cannot find FacesContext

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am now working with JSF/EJB 3.0. I use Netbeans 6.0 IDE, jboss 4.2.2 GA.
I here try to embed the JSF components in the project here I get the error repeatedly when I try to run the JSF page on browser. I get the deployment without any errors.

I added up the libraries as necessary jar files from the jboss dir..

I got the error as such..

ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.RuntimeException: Cannot find FacesContext
at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1796)
at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1613)
at org.apache.jsp.login_jsp._jspx_meth_h_005fform_005f0(login_jsp.java:112)
at org.apache.jsp.login_jsp._jspService(login_jsp.java:84)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this tag in your web.xml file??

<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

if not, make sure it is.
 
Bassam Al-Sarori
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And also remove the jsf-api and jsf-impl from the lib folder of your application because JBoss already contains JSF libs.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure that the request URL matches the url-pattern of the FacesServlet entry in web.xml. This way the request will be passed through the FacesServlet, which on its turn creates the FacesContext. Otherwise the JSF components in the JSP page will complain that the FacesContext cannot be found and hence this exception.

If the url-pattern is for example *.jsf, you should be invoking the page as /page.jsf, not as /page.jsp.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bassam Al-Sarori: your answers makes really no sense.
 
Bassam Al-Sarori
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just trying to help. I thought that there was a conflict between JSF libs inside the application and the server. Yes, your answer seems to make more sense because the exception is fired by JSP servlet.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's also all about the exception type and message.
 
Hari Dhanakoti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I altered the code as said above but the exception has changed now as such...

Exception sending context initialized event to listener instance of class org.jboss.web.jsf.integration.config.JBossJSFConfigureListener
java.lang.ClassCastException: com.sun.faces.application.ApplicationAssociate


I got the project running with normal JSF/Servlet in a web archive files but I am not sure what makes the project not running out along with EJB 3.0..
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you followed the answer of Bassam Al-Sarori? You shouldn't. Remove the ConfigureListener declaration from the web.xml.
 
Bassam Al-Sarori
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you remove the jsf-api and jsf-impl from the lib folder of your application?? This exception usually happens when your application contains these libraries and deployed under JBoss.

If you want to use your own JSF libs instead of using those in JBoss, insert this in your web.xml

<context-param>
<param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
<param-value>true</param-value>
</context-param>
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bauke Scholtz wrote:Make sure that the request URL matches the url-pattern of the FacesServlet entry in web.xml. This way the request will be passed through the FacesServlet, which on its turn creates the FacesContext. Otherwise the JSF components in the JSP page will complain that the FacesContext cannot be found and hence this exception.

If the url-pattern is for example *.jsf, you should be invoking the page as /page.jsf, not as /page.jsp.



I'm having this same issue.

I was running through this tutorial and I'm getting the same error. If the url doesn't match the XML mapping I get the requested resource is unavailable. Then I match it up and I get the Cannot find FacesContext.

Thoughts?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your web.xml (WAR deployment descriptor) maps "/faces/" to the Faces Servlet, your url will need to have /faces/ in it.

Related GlassFish 2.1 error output in my case:
StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.RuntimeException: Cannot find FacesContext
at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1811
 
Greenhorn
Posts: 1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I faced a problem which says that "Runtime exception - cannot find Faces Context"
I solved the problem .
I am using Eclipse 3.7 and Jboss 4.2.2 AS
The wrong thing i did was to include the JSF 1.2 Apache myfaces lib in to my project .

JBoss itself has jsf api installed and it conflicts with myfaces jsf api libraries .
If you included any jsf libraries into your project remove these . And remove any configurations that says anything about myfaces libraries in web.xml.
Wish that helps
 
Saloon Keeper
Posts: 28494
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The FacesContext is not a long-term object. It is constructed by the FacesServlet when an HTTP URL request is routed to the FacesServlet and it is destroyed as soon as the response to that request has been sent back to the client. Each request gets a new FacesContext. And since the FacesServlet is doing the construction and management of the FacesContext, any URL routed to anywhere BUT the FacesServlet won't get a FacesContext. That means regular servlets, non-JSF JSPs and JSF requests which don't match the URL routing pattern for the FacesServlet as defined in web.xml.



A note on JBoss and MyFaces. Apache MyFaces actually consists of several different sets of tag libraries. The Core JSF tagset provided by Myfaces will conflict with the Core JSF tagset that's part of JBoss, so you should not include it in your WAR. However, the extension tagsets such as MyFaces Tomahawk do not conflict and can safely be used in JBoss WARs.

The JBoss docs discuss these conflicts in detail, including how to use the MyFaces core tagset in place of the JBoss core tagset should the need arise.
 
Ranch Hand
Posts: 47
Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have same issue. I have eclipse 3.6 and tomcat. I placed the jsp-iml.jar and jsf-api.jar in the lib directory of tomacat and removed from application lib folder. when i provide the url

http://localhost:8080/HelloJSF/index.jsf or

http://localhost:8080/HelloJSF/faces/index.jsp

manualy in the browser, page is rendered.

when i run it from project->run as->run on server, throws exception and the url is

http://localhost:8080/HelloJSF/

Stacktrace:] with root cause
java.lang.RuntimeException: Cannot find FacesContext
at javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1852)
at javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1669)
at org.apache.jsp.index_jsp._jspx_meth_f_005fview_005f0(index_jsp.java:105)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Oct 5, 2011 9:15:31 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/HelloJSF] threw exception [An exception occurred processing JSP page /index.jsp at line 10

If I change url to http://localhost:8080/HelloJSF/index.jsf or
http://localhost:8080/HelloJSF/faces/index.jsp it works. What should i try?
 
bilal haider
Ranch Hand
Posts: 47
Windows XP Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried all the option. URL Pattern and Listener Configuration was already done by the tool. I placed the jsp-iml.jar and jsf-api.jar in the lib directory of tomacat and removed from application lib folder but it did not work.

I changed the content of index.jsp by removing from index.jsp. Now content of index.jsp are



and it works.

Why application throw exception when index.jsp contains these line and run from eclipse?
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic