MyEclipse: javax.servlet.ServletException: Cannot find FacesContext

cmmst82 - May 04, 2005 - 04:13 AM
Post subject: javax.servlet.ServletException: Cannot find FacesContext
I get the following error: javax.servlet.ServletException: Cannot find FacesContext when I try to view a .jsp in my browser.

I am using JBoss 4.0.1, Eclipse 3.0.2 with myEclipse plugin 3.8.
I am using trying to create a simple jsp using java server faces. I added the jsf capabilities via myeclipse->add JSF capabilities. I checked to make sure all the right .jar and .tld files are included. I also checked the web.xml files to make sure that the servlet-name and servlet-mapping included Faces Servlet and *.faces respectively.

Any help on how to clear this up would be appreciated.

Thanks,

cmmst82
support-rkalla - May 04, 2005 - 04:35 PM
Post subject:
What is the entire stack trace? Did you go line by line through our tutorial here: http://www.myeclipseide.com/images/tutorials/quickstarts/jsf/
cmmst82 - May 04, 2005 - 08:19 PM
Post subject:
I did go through the tutorial. I downloaded all the required programs. I created all the jsp files and the UserBean class as in the tutorial. I then built the project and received a bunch of errors:

FacesContext cannot be resolved or is not a type in UserBean.java. The javax.faces in the line import javax.faces.context.FacessContext is underlined red in the editor. It seems that eciplse cannot find the faces classes. I am also getting the same thing for all the jsf tags in the jsps.

I'm sure it's something I've overlooked and it's driving me crazy.
support-rkalla - May 04, 2005 - 11:12 PM
Post subject:
Quote:

FacesContext cannot be resolved or is not a type in UserBean.java. The javax.faces in the line import javax.faces.context.FacessContext is underlined red in the editor. It seems that eciplse cannot find the faces classes. I am also getting the same thing for all the jsf tags in the jsps.

It sounds like you are missing all the JSF JARs from your build path. Navigate to your Project Properties > Java Build Path > Libraries, then hit Add JAR, and navigate to your WebRoot/WEB-INF/lib dir and add ALL the JARs to your path. The errors should disappear.
cmmst82 - May 05, 2005 - 03:17 AM
Post subject:
That worked! Thank you!
cmmst82 - May 05, 2005 - 03:34 AM
Post subject:
Ok, I celebrated a little quick. All the errors in the build are gone. Everything compiled. Now, when I go to view the page I am getting that javax.servelt... error that I was getting before. The stacktrace is:

javax.servlet.ServletException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.userLogin_jsp._jspService(userLogin_jsp.java:97)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)


root cause

javax.servlet.jsp.JspException: Cannot find FacesContext
javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:405)
com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:105)
org.apache.jsp.userLogin_jsp._jspx_meth_f_view_0(userLogin_jsp.java:112)
org.apache.jsp.userLogin_jsp._jspService(userLogin_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)


I appreciate all your help, thanks.
cmmst82 - May 05, 2005 - 03:41 AM
Post subject:
I missed the beginning of the error in the stacktrace: ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
support-rkalla - May 05, 2005 - 05:07 PM
Post subject:
It looks like JSF is not getting deployed with your app, this IS a web project isn't it? Are you using the MyEclipse deployment tool to deploy the project? If so, can you navigate to the deployed directory and check the /lib dir and see that all the jsf JARs are there.
cmmst82 - May 05, 2005 - 05:59 PM
Post subject:
I went to the following dir: C:\jboss-4.0.1sp1\server\default\deploy\loginDemo.war\WEB-INF\lib and all the .jar files are there.
support-rkalla - May 05, 2005 - 06:09 PM
Post subject:
Please follow tips here, this is a setup issue: http://onesearch.sun.com/search/onesearch/index.jsp?qt=Cannot+find+FacesContext&subCat=siteforumid%3Ajava427&site=dev&qp=siteforumid%3Ajava427&chooseCat=javaall&col=developer-forums
cmmst82 - May 05, 2005 - 07:27 PM
Post subject:
The problem was simple; the userLogin.jsp needed to be userLogin.faces in the URL. Now I can celebrate! Thanks for your help.
mimi_grebici - Sep 27, 2006 - 02:53 PM
Post subject:
Hi

can you tell me please why that must be .faces instead of .jsp
because I have the same exception : javax.servlet.ServletException: Cannot find FacesContext

thank you
support-rkalla - Sep 27, 2006 - 05:34 PM
Post subject:
mimi,
Look at your web.xml file, you have mapped your FacesServlet to the "*.faces" extension most likely, if you don't access your pages using the .faces extension, then the FacesServlet is never triggered, and the FacesServlet does *a lot* of pre and post-processing of the pages before they load in order to maintain session state. So you have to 'trigger' the servlet, and the way that is done is by using a custom extension.
mimi_grebici - Sep 28, 2006 - 12:28 PM
Post subject:
Thank you for the response

what do I have to do if I want to use .jsp extension ?

I tried to replace *.faces by *.jsp but it does not work !!! I suppose that there is somme configurations before?!

web.wml

<?xml version="1.0" encoding="UTF-8" ?>
- <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
- <servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
- <servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>




another question ... I replaced the loaded jars (commons-beanutils.jar , commons-collections.jar , commons-digester.jar , commons-logging.jar) by (commons-beanutils-1.6.jar , commons-collections-2.1.1.jar , commons-digester-1.7.jar , commons-logging-1.0.4.jar) but that caused a problem !!!


thanks

mimi
support-rkalla - Sep 28, 2006 - 03:02 PM
Post subject:
Mimi,
As far as the extension question, that is a general JSF/Servlet mapping question that should like Google for. I would answer it if I knew, but I've never tried to map my FacesServlet to the same extension as the page it's processing.

Also, I don't undertand what you meant by replacing your JARs, did you do this in your project or in your Tomcat install? Did you remove the old ones? What was the error that it caused? This is not a MyEclipse issue either but if I can help you quickly, I will.
lhale - Nov 26, 2006 - 10:59 PM
Post subject: I'm still, after all the suggestions, getting no ClassFound
I've been at this problem described in this thread for days now. I've tried all the tricks mentioned here and all the tricks pointed to on the Sun site to ameliorate the problem of getting your JSF tutorial to work on jBoss 4.0.5 using the 1.1.4 faces libraries. The problem I'm having is centered exactly on the references to the javax.faces.application.FacesMessage and javax.faces.context.FacesContext found in the UserBean class (documented in your tutorial). BTW - I couldn;t help but NOTICE that your download of this project DOESN'T have any references to these two classes - care to clue me in why that might be? Could it be that you removed these so that you didn't have the same problem I'm running into? Let me know.

To rehash what exactly my problem is: here it is, just like the original poster:
"
root cause

javax.faces.FacesException: Unresolved compilation problems:
The import javax.faces cannot be resolved
The import javax.faces cannot be resolved
FacesContext cannot be resolved to a type
FacesContext cannot be resolved
FacesMessage cannot be resolved to a type
FacesMessage cannot be resolved to a type

org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:422)
org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:234)
org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


"

I got to believe it's some kind of magical faces context initialization that I need to do for the latest flavor of the faces stuff. But I have another faces project that seems to work with no apparent magic, but that project does not reference those two classes noted above (once again - what's so special about them???)

Do not ask me if I tried something that has already been discussed - I've tried EVERYTHING that was discussed, to no avail and anything else I could find that remotely might have a chance of fixing this problem. Is there a way that I can upload my whole project? I believe that is the only way you'll be able to help me out on this on (I am NOT a newbie).

-- Larry H
support-rkalla - Nov 27, 2006 - 12:59 PM
Post subject:
Larry,
To jump right to the cause sending us the project will probably be the fastest. Please do the following:

1) File > Export > Archive, and export your project to a ZIP file.
2) Email the ZIP file as an attachment to support@myeclipseide.com ATTN Riyad, with a link to this thread so I know why I'm getting the file.
3) BE sure to include steps on how to reproduce the problem. For example, deploy project to Tomcat, and click a certain link or something like that.

I'll evaluate the project and let you know what I find.
amir55 - Jun 11, 2007 - 09:36 PM
Post subject: Cannot find FacesContext using jsf spring
23:58:01,375 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: Cannot find FacesContext
at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:399)
at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:105)
at org.apache.jsp.index_jsp._jspx_meth_f_view_0(index_jsp.java:81)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:57)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:44)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:169)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke
hi all
it is really bothering me for the last 4 months to find a way from my consecutive errors using jsf-spring intergration on my Jboss and mysql.

now the last error is below. I do not want to choose another IDE as I bought fully licensed this IDE
this time stack errors is this
(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:595)
vijaysree9@gmail.com - Aug 16, 2007 - 08:45 AM
Post subject:
cmmst82 wrote:
Ok, I celebrated a little quick. All the errors in the build are gone. Everything compiled. Now, when I go to view the page I am getting that javax.servelt... error that I was getting before. The stacktrace is:

javax.servlet.ServletException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.userLogin_jsp._jspService(userLogin_jsp.java:97)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)


root cause

javax.servlet.jsp.JspException: Cannot find FacesContext
javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:405)
com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:105)
org.apache.jsp.userLogin_jsp._jspx_meth_f_view_0(userLogin_jsp.java:112)
org.apache.jsp.userLogin_jsp._jspService(userLogin_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)


I appreciate all your help, thanks.

support-rkalla - Aug 16, 2007 - 06:17 PM
Post subject:
vijay,
You will get that error when you don't use the extension to access the page that is mapped to JSF. For example, index.faces instead of index.jsp.
michaelc - Sep 04, 2007 - 04:29 AM
Post subject: I found the following to work fine
in the web.xml add the following mapping
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

then in the index.jsp do a forward.
<jsp:forward page="faces/welcome.jsp"/>

in your faces-config
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>welcome</from-outcome>
<to-view-id>/welcome.jsp</to-view-id>
<redirect/>
</navigation-case>

from this point forward the control is within faces.
I had the same issue and found this in a tutoral I was working on.
All times are GMT - 6 Hours
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits