Boa Noite Galera…
To estudando uma apostila de JSF aqui da Algaworks, mais durante a complicação de uma página aqui me deparei com um erro que não estou conseguindo encontrar, vou postar as seguintes classes que o arquivo JSP que criei, e também o erro…
Classe Contato
package com.algaworks.dwjsf.dominio;
public class Contato {
private String nome;
private String sexo;
private String endereco;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getSexo() {
return sexo;
}
public void setSexo(String sexo) {
this.sexo = sexo;
}
}
Classe AgendaContatoBean
package com.algaworks.dwjsf.visao;
import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ActionEvent;
import com.algaworks.dwjsf.dominio.Contato;
public class AgendaContatoBean {
private List<Contato> contatos;
private Contato contato;
public AgendaContatoBean() {
this.setContatos(new ArrayList<Contato>());
this.setContato(new Contato());
}
public void incluirContato(ActionEvent event) {
this.getContatos().add(this.getContato());
this.setContato(new Contato());
}
public List<Contato> getContatos() {
return contatos;
}
public void setContatos(List<Contato> contatos) {
this.contatos = contatos;
}
public Contato getContato() {
return contato;
}
public void setContato(Contato contato) {
this.contato = contato;
}
}
Arquivo JSP
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<f:view>
<head>
<title>Agenda de Contatos</title>
</head>
<body>
<h:form>
<h:outputText value="Nome: "/>
<h:inputText value="#{agendaContatoBean.contato.nome }"/>
<br/>
<h:outputText value="Endereço: "/>
<h:inputText value="#{agendaContatoBean.contato.endereco }" />
<br/>
<h:outputText value="Sexo: " />
<h:inputText value="#{agendaContatoBean.contato.sexo }"/>
<br/>
<h:commandButton
actionListener="#{agendaContatoBean.incluirContato}"
value="Incluir" />
<br/><br/>
<h:dataTable var="obj" value="#{agendaContatoBean.contatos }"
border="1" width="100%">
<h:column>
<f:facet name="header">
<h:outputText value="Nome"/>
</f:facet>
<h:outputText value="#{obj.nome}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Endereço"/>
</f:facet>
<h:outputText value="#{obj.endereco}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Sexo"/>
</f:facet>
<h:outputText value="#{obj.sexo}"/>
</h:column>
</h:dataTable>
</h:form>
</body>
</f:view>
</html>
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: /agendaContato.jsp(15,18) '#{agendaContatoBean.contato.nome }' Target Unreachable, identifier 'agendaContatoBean' resolved to null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:422)
root cause
org.apache.jasper.el.JspPropertyNotFoundException: /agendaContato.jsp(20,15) '#{agendaContatoBean.contato.nome }' Target Unreachable, identifier 'agendaContatoBean' resolved to null
org.apache.jasper.el.JspValueExpression.getType(JspValueExpression.java:61)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
javax.faces.component.UIInput.validate(UIInput.java:960)
javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
javax.faces.component.UIInput.processValidators(UIInput.java:698)
javax.faces.component.UIForm.processValidators(UIForm.java:253)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
Apache Tomcat/6.0.16