Bem pessoal, estou começando agora com JSF e não estou conseguindo rodar seguinte exemplo:
MeuBean
package meupacote;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
public class MeuBean
{
private String nome = null;
public void setNome(String nome)
{
this.nome = nome;
}
public String getNome()
{
return nome;
}
public String acao()
{
boolean sucesso = true;
FacesContext context = FacesContext.getCurrentInstance();
if(nome != null)
{
for(int i = 0; i < nome.length(); i++)
{
char c = nome.charAt(i);
if(!(Character.isLetter(c)) && ! Character.isSpaceChar(c))
{
String msg = "Digite somente caracteres alfabéticos.";
FacesMessage message = new FacesMessage(msg);
context.addMessage("formulario", message);
sucesso = false;
break;
}
}
}
else
{
sucesso = false;
}
return (sucesso ? "sucesso" : "falha");
}
}
trabComJSF.jsp
<%@ page language="java" contentType="text/html" pageEncoding="ISO-8859-1" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Trabalhando com JSF</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<f:view>
<h:form id="formulario">
Digite seu nome:
<h:inputText id="nome" value="#{MeuBean.nome}" required="true" />
<h:commandButton action="#{MeuBean.acao }" value="Enviar" id="submit" />
<br/>
<h:messages/>
</h:form>
</f:view>
</body>
</html>
boasVindas.jsp
<%@ page language="java" contentType="text/html" pageEncoding="ISO-8859-1" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Trabalhando com JSF</title>
</head>
<body>
<f:view>
olá <h:outputText value="#{MeuBean.nome }"/><br/>
</f:view>
</body>
</html>
faces-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD Javaserver Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>MeuBean</managed-bean-name>
<managed-bean-class>meupacote.MeuBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/trabComJSF.jsp</from-view-id>
<navigation-case>
<from-outcome>sucesso</from-outcome>
<to-view-id>/boasVindas.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>falha</from-outcome>
<to-view-id>/trabComJSF.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
web.xml
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<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>*.jsf</url-pattern>
</servlet-mapping>
</web-app>
Está lançando a seguinte exceção:
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find FacesContext
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find FacesContext
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.trabComJSF_jsp._jspService(trabComJSF_jsp.java:94)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
javax.servlet.jsp.JspException: Cannot find FacesContext
javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:427)
com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:125)
org.apache.jsp.trabComJSF_jsp._jspx_meth_f_005fview_005f0(trabComJSF_jsp.java:109)
org.apache.jsp.trabComJSF_jsp._jspService(trabComJSF_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Alguem poderia me ajudar?
Value!!