- This topic has 20 replies, 7 voices, and was last updated 17 years, 8 months ago by
Michaelcford.
-
AuthorPosts
-
cmmst82MemberI 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
Riyad KallaMemberWhat is the entire stack trace? Did you go line by line through our tutorial here: http://www.myeclipseide.com/images/tutorials/quickstarts/jsf/
cmmst82MemberI 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.
Riyad KallaMemberFacesContext 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.
cmmst82MemberThat worked! Thank you!
cmmst82MemberOk, 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.
cmmst82MemberI missed the beginning of the error in the stacktrace: ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
Riyad KallaMemberIt 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.
cmmst82MemberI 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.
Riyad KallaMemberPlease 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
cmmst82MemberThe problem was simple; the userLogin.jsp needed to be userLogin.faces in the URL. Now I can celebrate! Thanks for your help.
mimi_grebiciMemberHi
can you tell me please why that must be .faces instead of .jsp
because I have the same exception : javax.servlet.ServletException: Cannot find FacesContextthank you
Riyad KallaMembermimi,
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_grebiciMemberThank 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
Riyad KallaMemberMimi,
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.
-
AuthorPosts