• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1591
  • Last Modified:

java.lang.RuntimeException: Cannot find FacesContext from simple JSP pag?

Hi,

I am trying to run this simple jsp page using jsf to display data from mysql.
This is what I am getting.
I suspect my config files are wrong.
can you help?

<?xml version='1.0' encoding='UTF-8'?>

<!-- =========== FULL CONFIGURATION FILE ================================== -->

<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">

<managed-bean>
<managed-bean-name>chemSearchHistoryDs</managed-bean-name>
<managed-bean-class>ChemSearchHistoryDs</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

</faces-config>

Open in new window

ype Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /DisplayData.jsp at line 14

11: 
12: 
13: 
14: <f:view>
15: <html>
16:     <head>
17:         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


Stacktrace:
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause

java.lang.RuntimeException: Cannot find FacesContext
	javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1811)
	javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1628)
	org.apache.jsp.DisplayData_jsp._jspx_meth_f_005fview_005f0(DisplayData_jsp.java:105)
	org.apache.jsp.DisplayData_jsp._jspService(DisplayData_jsp.java:82)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.14 logs.

Open in new window

<?xml version="1.0" encoding="UTF-8"?>

<web-app 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_3_0.xsd"
	 version="3.0">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

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

<!-- Faces Servlet -->

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>


<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping> 


</web-app>

Open in new window

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:view>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
        <div>
            <h:dataTable id="dt1" value="#{chemSearchHistoryDs.chemSearchList}" var="item" bgcolor="#F1F1F1" border="10" cellpadding="5" cellspacing="3" rows="4" width="50%" dir="LTR" frame="hsides" rules="all" summary="This is a JSF code to create dataTable." >

                <f:facet name="header">
                    <h:outputText value="This is 'dataTable' demo" />
                </f:facet> 

                <h:column>
                    <f:facet name="header">
                        <h:outputText value="ID" />
                    </f:facet> 
                    <h:outputText style="" value="#{item.chemID}" ></h:outputText>
                </h:column>

Open in new window

0
dkim18
Asked:
dkim18
  • 2
  • 2
1 Solution
 
Pramod KumarCommented:
Please ensure all the JSF libraries are present in your deployed project: jsf-api, jsf-impl etc.
0
 
dkim18Author Commented:
I have JSF 1.2 lib attached. They are all there.
0
 
Pramod KumarCommented:
you mean the .jar are already exists under: WEB-INF/lib
0
 
dkim18Author Commented:
I am using the netbean and when it builds and deploys OK.
I also see those lib jar files.

My example index page loads fine.
When I try to access this DisplayData.jsp page, it is bugging out.

Am I not supposed to access this page directly?
Do I need to access the uri differently?
It is driving me nut!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now