E ai pessoal beleza?
Estou estudando JSF com o livro Dominando Java Server Faces e Facelets…
Porem, quando eu tento executar o primeiro exemplo me da esse erro:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error testing property 'nome' in bean of type null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)
root cause
javax.faces.el.PropertyNotFoundException: Error testing property 'nome' in bean of type null
com.sun.faces.el.PropertyResolverImpl.getType(PropertyResolverImpl.java:342)
com.sun.faces.el.impl.ArraySuffix.getType(ArraySuffix.java:240)
com.sun.faces.el.impl.ComplexValue.getType(ComplexValue.java:208)
com.sun.faces.el.ValueBindingImpl.getType(ValueBindingImpl.java:345)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:111)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:713)
javax.faces.component.UIInput.validate(UIInput.java:638)
javax.faces.component.UIInput.executeValidate(UIInput.java:849)
javax.faces.component.UIInput.processValidators(UIInput.java:412)
javax.faces.component.UIForm.processValidators(UIForm.java:170)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:912)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:342)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:78)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.25
Seguem as classes e as paginas:
MeuBean.java
package br.com.integrator;
public class MeuBean {
private String nome;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
Controle.java
package br.com.controller;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import br.com.integrator.MeuBean;
public class Controle {
private MeuBean meuBean;
public MeuBean getMeuBean() {
return meuBean;
}
public void setMeuBean(MeuBean meuBean) {
this.meuBean = meuBean;
}
public Controle(){
meuBean = new MeuBean();
}
//Metodo que sera acionado pelo botao
public String acao(){
boolean sucesso = true;
FacesContext context = FacesContext.getCurrentInstance();
if(meuBean.getNome() != null){
for(int i = 0; i < meuBean.getNome().length(); i ++){
char c = meuBean.getNome().charAt(i);
if(!Character.isLetter(c) && Character.isSpaceChar(c)){
String msg = "Digite somente caracteres alfabéticos";
FacesMessage mensagem = new FacesMessage(msg);
context.addMessage("formulario", mensagem);
sucesso = false;
break;
}
}
}
else{
sucesso = false;
}
return (sucesso ? "sucesso": "falha");
}
}
TrabComJSF
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<head>
<title>Trabalhe com JSF</title>
</head>
<body>
<f:view>
<h:form id="formulario">
Digite o seu nome:
<h:inputText id="nome" value="#{meuBean.nome}" required="true" />
<h:commandButton action="#{controle.acao}" value="enviar" id="submit" />
<h:messages />
</h:form>
</f:view>
</body>
</html>
Faces Config
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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>
<description>User Name Bean</description>
<managed-bean-name>controle</managed-bean-name>
<managed-bean-class>br.com.controller.Controle</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>name</property-name>
<property-class>java.lang.String</property-class>
<value/>
</managed-property>
</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>
<redirect/>
</navigation-case>
</navigation-rule>
</faces-config>
web.xml
<?xml version="1.0"?>
<web-app version="2.5" 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_2_5.xsd">
<display-name>TrabComJSF</display-name>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</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>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
O que é que pode estar errado galera?
Obrigado a todos