Boa tarde pessoal.
Estou seguindo essa video aula http://www.youtube.com/watch?v=VvdRKdDY7VM e cheguei até a parte 5 acompanhei todos os testes e todos ficaram certos, no entanto, na hora do submit da erro NullPointerException bem no final da aula 5 (esse erro não aparece na aula mas revisei todo o projeto, imports e tudo está idêntico).
Não estou conseguindo identificar a origem do erro debuguei o projeto na classe Contato (getNome) ele retorna o nome que digitei no input como deveria ser mas depois disso não consigo mais debugar.
index.xhtml
[code]<?xml version=‘1.0’ encoding=‘UTF-8’ ?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”
xmlns:h=“http://java.sun.com/jsf/html”>
<h:head>
<title>Sistema Agenda</title>
</h:head>
<h:body>
<center><h1>Sistema Agenda</h1></center>
<h:form>
<h:outputText value=“Nome”/>
<h:inputText id=“nome” value="#{contatosController.contatos.nome}"/>
<h:outputText value=“E-mail”/>
<h:inputText id=“email” value="#{contatosController.contatos.email}"/>
<h:outputText value=“Telefone”/>
<h:inputText id=“telefone” value="#{contatosController.contatos.telefone}"/>
<h:outputText value=“Celular”/>
<h:inputText id=“celular” value="#{contatosController.contatos.celular}"/>
<h:commandButton value="Salvar" id="salva" actionListener="#{contatosController.adicionar(actionEvent)}"/>
</h:form>
</h:body>
</html>[/code]hibernate.cfg.xml<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/agenda</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="br.com.agenda.model.Contatos"/>
</session-factory>
</hibernate-configuration>
HibernateUtil.java[code]/*
- To change this template, choose Tools | Templates
- and open the template in the editor.
*/
package br.com.agenda.util;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
/**
-
Hibernate Utility class with a convenient method to get Session Factory
-
object.
-
@author 18122012
*/
public class HibernateUtil {private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
[/code]web.xml<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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_3_0.xsd"> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</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>*.xhtml</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>index.xhtml</welcome-file> </welcome-file-list> </web-app>
InterfaceContatos.java[code]/* -
To change this template, choose Tools | Templates
-
and open the template in the editor.
*/
package br.com.agenda.dao;
import br.com.agenda.model.Contatos;
import java.util.List;
/**
*
-
@author 18122012
*/
public interface InterfaceContatos {public Contatos getContatos(Long id);
public void salvar(Contatos contatos);
public void remover(Contatos contatos);
public void atualizar(Contatos contatos);
public List<Contatos> list();
}[/code]Contatos.java[code]/* -
To change this template, choose Tools | Templates
-
and open the template in the editor.
*/
package br.com.agenda.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
*
-
@author 18122012
*/
@Entity(name = “contatos”)
public class Contatos implements Serializable {@Id
@GeneratedValue
private Long id;
private String nome;
private String email;
private String telefone;
private String celular;public Long getId() {
return id;
}public void setId(Long id) {
this.id = id;
}public String getNome() {
return nome;
}public void setNome(String nome) {
this.nome = nome;
}public String getEmail() {
return email;
}public void setEmail(String email) {
this.email = email;
}public String getTelefone() {
return telefone;
}public void setTelefone(String telefone) {
this.telefone = telefone;
}public String getCelular() {
return celular;
}public void setCelular(String celular) {
this.celular = celular;
}
}[/code]ContatosDao.java[code]/* -
To change this template, choose Tools | Templates
-
and open the template in the editor.
*/
package br.com.agenda.dao;
import br.com.agenda.model.Contatos;
import br.com.agenda.util.HibernateUtil;
import java.util.List;
import org.hibernate.Session;
/**
*
-
@author 18122012
*/
public class ContatosDao implements InterfaceContatos {@Override
public Contatos getContatos(Long id) {
Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
return (Contatos) ss.load(Contatos.class, id);
}@Override
public void salvar(Contatos contatos) {
Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
ss.beginTransaction();
ss.save(contatos);
ss.beginTransaction().commit();
}@Override
public void remover(Contatos contatos) {
Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
ss.beginTransaction();
ss.delete(contatos);
ss.beginTransaction().commit();
}@Override
public void atualizar(Contatos contatos) {
Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
ss.beginTransaction();
ss.update(contatos);
ss.beginTransaction().commit();
}@Override
public List<Contatos> list() {
Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
ss.beginTransaction();
List lista = ss.createQuery(“from contatos”).list();
ss.beginTransaction().commit();
return lista;
}
}[/code]ContatosController.java[code]/* -
To change this template, choose Tools | Templates
-
and open the template in the editor.
*/
package br.com.agenda.controller;
import br.com.agenda.dao.ContatosDao;
import br.com.agenda.dao.InterfaceContatos;
import br.com.agenda.model.Contatos;
import java.awt.event.ActionEvent;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
/**
*
-
@author 18122012
*/
@ManagedBean
@SessionScoped
public class ContatosController {private Contatos contatos;
private DataModel listaContatos;public Contatos getContatos() {
if (this.contatos == null) {
this.contatos = new Contatos();
}
return contatos;
}public void setContatos(Contatos contatos) {
this.contatos = contatos;
}public DataModel getListaContatos() {
List<Contatos> lista = new ContatosDao().list();
listaContatos = new ListDataModel(lista);
return listaContatos;
}public void prepararAdicionarContato(ActionEvent actionEvent) {
contatos = new Contatos();
}public void prepararAlterarContato(ActionEvent actionEvent) {
contatos = (Contatos) (listaContatos.getRowData());
}public void adicionar(ActionEvent actionEvent) {
InterfaceContatos dao = new ContatosDao();
dao.salvar(contatos);
}public void alterar(ActionEvent actionEvent) {
InterfaceContatos dao = new ContatosDao();
dao.atualizar(contatos);
}public String excluir() {
Contatos contato = (Contatos) (listaContatos.getRowData());
InterfaceContatos dao = new ContatosDao();
dao.remover(contato);
return “index”;
}
}[/code]Esse é o log que aparece no console do netBeans
Ago 02, 2013 4:56:22 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
Ago 02, 2013 4:56:22 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
Ago 02, 2013 4:56:22 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/T02PI] startup failed due to previous errors
Ago 02, 2013 4:56:22 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [“http-bio-8084”]
Ago 02, 2013 4:56:22 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [“ajp-bio-8009”]
Ago 02, 2013 4:56:22 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6580 ms
Ago 02, 2013 4:56:27 PM org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/Agenda]
Ago 02, 2013 4:56:27 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\Users\18122012\AppData\Roaming\NetBeans\7.3\apache-tomcat-7.0.34.0_base\conf\Catalina\localhost\Agenda.xml
Ago 02, 2013 4:56:29 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Inicializando Mojarra 2.1.13 ( 20120907-1514) para o contexto ‘/Agenda’
Ago 02, 2013 4:56:29 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: Anotações PostConstruct/PreDestroy presentes. Os métodos ManagedBeans marcados com essas anotações informarão as anotações processadas.
Ago 02, 2013 4:56:29 PM org.primefaces.webapp.PostConstructApplicationEventListener processEvent
INFO: Running on PrimeFaces 3.4
Ago 02, 2013 4:56:30 PM org.apache.catalina.util.LifecycleBase start
INFO: The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Agenda]] after start() had already been called. The second call will be ignored.
Ago 02, 2013 4:56:32 PM com.sun.faces.context.SessionMap put
WARNING: JSF1063: AVISO! Definindo valor de atributo não serializável em HttpSession (chave: contatosController, classe do valor: br.com.agenda.controller.ContatosController).
Listening for transport dt_shmem at address: tomcat_shared_memory_id
Essa descrição aparece no navegador StackTrace
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.apache.el.util.ReflectionUtil.isAssignableFrom(ReflectionUtil.java:319)
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:185)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148 )
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88 )
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118 )
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118 )
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Não sei se isso ajuda ComponentTree também do navegador
<UIViewRoot id=“j_id1” inView=“true” locale=“pt_BR” renderKitId=“HTML_BASIC” rendered=“true” transient=“false” viewId="/index.xhtml">
<?xml version=‘1.0’ encoding=‘UTF-8’ ?> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<UIOutput id=“j_idt4” inView=“true” rendered=“true” transient=“false”>
<title>Sistema Agenda</title>
</UIOutput>
<UIOutput id=“j_idt6” inView=“true” rendered=“true” transient=“false”>
<center><h1>Sistema Agenda</h1></center>
<HtmlForm enctype=“application/x-www-form-urlencoded” id=“j_idt8” inView=“true” prependId=“true” rendered=“true” submitted=“true” transient=“false”>
<HtmlOutputText escape=“true” id=“j_idt9” inView=“true” rendered=“true” transient=“false” value=“Nome”/>
<HtmlInputText disabled=“false” id=“nome” immediate=“false” inView=“true” localValueSet=“false” maxlength="-2147483648" readonly=“false” rendered=“true” required=“false” size="-2147483648" transient=“false” valid=“true” value=“1”/>
<HtmlOutputText escape=“true” id=“j_idt10” inView=“true” rendered=“true” transient=“false” value=“E-mail”/>
<HtmlInputText disabled=“false” id=“email” immediate=“false” inView=“true” localValueSet=“false” maxlength="-2147483648" readonly=“false” rendered=“true” required=“false” size="-2147483648" transient=“false” valid=“true” value=“1@1”/>
<HtmlOutputText escape=“true” id=“j_idt11” inView=“true” rendered=“true” transient=“false” value=“Telefone”/>
<HtmlInputText disabled=“false” id=“telefone” immediate=“false” inView=“true” localValueSet=“false” maxlength="-2147483648" readonly=“false” rendered=“true” required=“false” size="-2147483648" transient=“false” valid=“true” value=“1”/>
<HtmlOutputText escape=“true” id=“j_idt12” inView=“true” rendered=“true” transient=“false” value=“Celular”/>
<HtmlInputText disabled=“false” id=“celular” immediate=“false” inView=“true” localValueSet=“false” maxlength="-2147483648" readonly=“false” rendered=“true” required=“false” size="-2147483648" transient=“false” valid=“true” value=“11”/>
<HtmlCommandButton disabled=“false” id=“salva” immediate=“false” inView=“true” readonly=“false” rendered=“true” transient=“false” type=“submit” value=“Salvar”/>
</HtmlForm>
</UIOutput>
</html>
</UIViewRoot>