e ai rapaziada, blz…to rodando um exemplo de jsf, e gerou o seguinte erro:
javax.servlet.ServletException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.index_jsp._jspService(index_jsp.java:78)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
- ta acusando q nao ta encontrando FacesContext…eu to usando o netbeans para este exemplo…ele ja vem integrado o jsf…
valeuu
isso acontece pq o netbeans mapeia a instancia do FacesServlet para /faces/* vc pode ver isso no web.xml
vc pode fazer um index.jsp que redireciona para /faces/seuJsp.jsp
algo como <html>
<head>
</head>
<body>
<jsp:forward page="faces/index2.jsp" />
</body>
</html>
vc pode ver um exemplo disso no The Java EE 5 Tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/JSFIntro4.html#wp114963
embora, sinceramente, não goste dessa solução… se alguém conhecer uma melhor… informe-nos :lol:
blz…fiz o index e redirecionei para a minha pagina principal, que tem dois links que vao chamar a pagina inserir.jsp e buscar.jsp…ta gerando erro quando tento acessar estas paginass…
** a pagina principal é a seguinte:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<html>
<head>
<title>Exemplo JSF</title>
</head>
<body>
<f:view>
<h:form>
<center>
<h1>Agenda</h1>
<br>
<h3>
<h:outputLink value="inserir.jsf">
<f:verbatim>Inserir</f:verbatim>
</h:outputLink>
<br><br>
<h:outputLink value="buscar.jsf">
<f:verbatim>Buscar</f:verbatim>
</h:outputLink>
</h3>
</center>
</h:form>
</f:view>
</body>
</html>
** o arquivo faces-config:
<faces-config>
<navigation-rule>
<from-view-id>/buscar.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/sucesso_busca.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/falha_busca.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/inserir.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/sucesso_insercao.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/falha_insercao.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>agenda</managed-bean-name>
<managed-bean-class>AgendaDB</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
*** arquivo web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlnssi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee <a href="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" target="_blank" rel="nofollow">http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd</a>">
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</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>
<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>
<session-config><session-timeout>
30
</session-timeout></session-config><welcome-file-list><welcome-file>
index.jsp
</welcome-file></welcome-file-list></web-app>
*** o erro gerado:
HTTP Status 404 - /exemplo-jsf/inserir.jsf
type Status report
message /exemplo-jsf/inserir.jsf
description The requested resource (/exemplo-jsf/inserir.jsf) is not available.
Apache Tomcat/5.5.9
***** valeu
bom,
você está mapeando para usar uma url como:
localhost:8080/suaApp/faces/diretorio/index.jsp
mas está usando como:
localhost:8080/suaApp/diretorio/index.jsf
Aconselho antes de começar com JSF passar um pouco sobre Servlets…
:joia:
Use:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Ao invés de
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>