Hello,
I am a programmer and pretty much new to the
JSF technology.
I have a problem running an example from a book, "Beginning
Java EE 5".
Hope somebody can help out.
**************************************************************************
First the error message I get:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in
JSP: /searchForm.jsp:12
9: <meta http-equiv="Content-Type" content="text/html; charset=ISO-
10:
11: <html>
12: <f:view>
13: <head>
14: <title>Freedom Airlines Online Flight Reservation System</title>
15: </head>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
javax.servlet.ServletException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.searchForm_jsp._jspService(searchForm_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
root cause
javax.servlet.jsp.JspException: Cannot find FacesContext
javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:405)
org.apache.myfaces.taglib.core.ViewTag.doStartTag(ViewTag.java:71)
org.apache.jsp.searchForm_jsp._jspx_meth_f_view_0(searchForm_jsp.java:98)
org.apache.jsp.searchForm_jsp._jspService(searchForm_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.16 logs.
**************************************************************************
Here's my web.xml:
<?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/web-app_2_5.xsd"
version="2.5">
<display-name>Jsf_Ex01 - Simple JSF Application</display-name>
<
servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
**************************************************************************
Here's my faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config 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/web-facesconfig_1_2.xsd"
version="1.2">
<navigation-rule>
<from-view-id>/searchForm.jsp</from-view-id>
<navigation-case>
<from-outcome>submit</from-outcome>
<to-view-id>/searchResults.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>flight</managed-bean-name>
<managed-bean-class>jsf.test1.FlightSearch</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
**************************************************************************
Here's my index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Flight Search</title>
</head>
<body>
<meta http-equiv="Refresh" content= "0; URL=searchForm.faces"/>
</body>
</html>
***************************************************************************
Here is my first jsf page, searchForm.jsf:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
<html>
<f:view>
<head>
<title>Freedom Airlines Online Flight Reservation System</title>
</head>
<body>
<h:form>
<h2>Search Flights</h2>
<table>
<tr><td colspan="4">Where and when do you want to travel?</td></tr>
<tr>
<td colspan="2">Leaving from:</td>
<td colspan="2">Going to:</td>
</tr>
<tr>
<td colspan="2">
<h:inputText value="#{flight.origination}" size="35"/>
</td>
<td colspan="2">
<h:inputText value="#{flight.destination}" size="35"/>
</td>
</tr>
<tr>
<td colspan="2">Departing:</td>
<td colspan="2">Returning:</td>
</tr>
<tr>
<td>
<h:inputText value="#{flight.departDate}"/>
</td>
<td>
<h:inputText value="#{flight.departTime}"/>
</td>
<td>
<h:inputText value="#{flight.returnDate}"/>
</td>
<td>
<h:inputText value="#{flight.returnTime}"/>
</td>
</tr>
</table>
<p>
<h:commandButton value="Search" action="submit"/>
</p>
</h:form>
</body>
</f:view>
</html>
***************************************************************************
Here is my second jsf page, searchResults.jsf:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<html>
<f:view>
<head>
<title>Freedom Airlines Online Flight Reservation System</title>
</head>
<body>
<h3>You entered these search parameters</h3>
<p>Origination: <h
utputText value="#{flight.origination}"/>
<p>Depart date: <h
utputText value="#{flight.departDate}"/>
<p>Depart time: <h
utputText value="#{flight.departTime}"/>
<p>Destination: <h
utputText value="#{flight.destination}"/>
<p>Return date: <h
utputText value="#{flight.returnDate}"/>
<p>Return time: <h
utputText value="#{flight.returnTime}"/>
<p>Trip type : <h
utputText value="#{flight.tripType}"/>
</body>
</f:view>
</html>
</body>
</html>
***************************************************************************
And here's my java bean, FlightSearc.java:
package jsf.test1;
public class FlightSearch {
String origination;
String destination;
String departDate;
String departTime;
String returnDate;
String returnTime;
public String getDepartDate() {
return departDate;
}
public void setDepartDate(String departDate) {
this.departDate = departDate;
}
public String getDepartTime() {
return departTime;
}
public void setDepartTime(String departTime) {
this.departTime = departTime;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public String getOrigination() {
return origination;
}
public void setOrigination(String origination) {
this.origination = origination;
}
public String getReturnDate() {
return returnDate;
}
public void setReturnDate(String returnDate) {
this.returnDate = returnDate;
}
public String getReturnTime() {
return returnTime;
}
public void setReturnTime(String returnTime) {
this.returnTime = returnTime;
}
}
***************************************************************************
Can somebody please help? I've been debugging it for hours and I can't find the error. I have placed all 6 JSF jars inside the WEB-INF/lib directory, placed them inside my Java build path, and inluded them in my packaging cofigurations - but still I get an error message. I am thinking it might be with some configurations in Eclipse that I missed out. Please help, 'coz I really need to get to the next sections of this book. Thanks a lot.
-eugene