JSF - Managed Bean - Desesperado

8 respostas
anderson.bonavides

Bom dia pessoal,
Estou com o seguinte problema. Meu Managed Bean quando vai cadastrar um usuário gera o seguinte erro:


javax.servlet.ServletException: #{usuario.cadastrarUsuario}: javax.faces.el.EvaluationException: java.lang.NullPointerException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:225)

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: #{usuario.cadastrarUsuario}: javax.faces.el.EvaluationException: java.lang.NullPointerException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:225)


Alguem poderia me dar uma luz do que seria?

Grato.

8 Respostas

sfing

Posta o codigo !

Mas acho que precisa instanciar o objeto que esta usando, não tenho certeza, algumas vezes que tive essa mensagem era isso !!

peerless

anderson.bonavides:
Bom dia pessoal,
Estou com o seguinte problema. Meu Managed Bean quando vai cadastrar um usuário gera o seguinte erro:


javax.servlet.ServletException: #{usuario.cadastrarUsuario}: javax.faces.el.EvaluationException: java.lang.NullPointerException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:225)

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: #{usuario.cadastrarUsuario}: javax.faces.el.EvaluationException: java.lang.NullPointerException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:225)


Alguem poderia me dar uma luz do que seria?

Grato.

Cola o seu MB aí, e utiliza a formatação de código, se possível.

anderson.bonavides
Managed Bean
package br.com.jampasoftwaredevelopment.view;

import br.com.jampasoftwaredevelopment.business.Operacoes;
import br.com.jampasoftwaredevelopment.model.Usuario;


public class UsuarioMB {
	
	//public enum Tipo{Cliente, Gerente, Desenvolvedor};
	private String nome;
	private String telefone;
	private String email;
	private String login;
	private String senha;
	private String tipo;
	
	public UsuarioMB(){
		
	}
	
	public UsuarioMB(String nome, String telefone, String email, String login,
			String senha, String tipo) {
		super();
		this.nome = nome;
		this.telefone = telefone;
		this.email = email;
		this.login = login;
		this.senha = senha;
		this.tipo = tipo;
	}

	
	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getTelefone() {
		return telefone;
	}

	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public String getTipo() {
		return tipo;
	}

	public void setTipo(String tipo) {
		this.tipo = tipo;
	}

	public String validarUsuario(){
		
		return "gerente";
	}
	
	
	public String cadastrarUsuario(){
		System.out.println("Nome: "+this.nome);
		System.out.println("Telefone: "+this.telefone);
		System.out.println("Email: "+this.email);
		System.out.println("Login: "+this.login);
		System.out.println("Senha: "+this.senha);
		System.out.println("Tipo: "+this.tipo);
		
		Operacoes<Usuario> op = new Operacoes<Usuario>();
		Usuario user = new Usuario();		
		user.setNome(this.nome);
		user.setTelefone(this.telefone);
		user.setEmail(this.email);
		user.setLogin(this.login);
		user.setSenha(this.senha);
		user.setTipo(this.tipo);
		
		op.inserir(user);		
		
		return "sucesso";
	}
}

Percebi também que o erro acontece quando chega na minha classe BaseDao.
Classe BaseDao

public class BaseDao<T> {
	private EntityManagerFactory factory = null;
	private EntityManager manager = null;

	public BaseDao() {
		factory = Persistence.createEntityManagerFactory("pu1"); //ACONTECE QUANDO CHEGA AKI
		manager = factory.createEntityManager();
	}

	public void inserir(T obj) {
		EntityTransaction transaction = manager.getTransaction();
		try {
			transaction.begin();
			manager.persist(obj);
			transaction.commit();
		}
		catch (Exception e) {
			transaction.rollback();
			System.err.println("Erro: " + e.getMessage());
		}finally {
			manager.close();
		}
	}

}

Pessoal vou postar o erro completo.

Por favor me ajudem.

Grato.

anderson.bonavides

6/05/2008 12:08:08 com.sun.faces.lifecycle.InvokeApplicationPhase execute SEVERE: #{usuario.cadastrarUsuario}: javax.faces.el.EvaluationException: java.lang.NullPointerException javax.faces.FacesException: #{usuario.cadastrarUsuario}: javax.faces.el.EvaluationException: java.lang.NullPointerException at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) at javax.faces.component.UICommand.broadcast(UICommand.java:332) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:287) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:401) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:95) at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:268) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:150) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92) ... 19 more Caused by: java.lang.NullPointerException at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:120) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27) at br.com.jampasoftwaredevelopment.persistence.BaseDao.<init>(BaseDao.java:15) at br.com.jampasoftwaredevelopment.business.Operacoes.inserir(Operacoes.java:9) at br.com.jampasoftwaredevelopment.view.UsuarioMB.cadastrarUsuario(UsuarioMB.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:146) ... 20 more 06/05/2008 12:08:08 org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet Faces Servlet threw exception java.lang.NullPointerException at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:120) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27) at br.com.jampasoftwaredevelopment.persistence.BaseDao.<init>(BaseDao.java:15) at br.com.jampasoftwaredevelopment.business.Operacoes.inserir(Operacoes.java:9) at br.com.jampasoftwaredevelopment.view.UsuarioMB.cadastrarUsuario(UsuarioMB.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:146) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:92) at javax.faces.component.UICommand.broadcast(UICommand.java:332) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:287) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:401) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:95) at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:268) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:110) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:213) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619)

V

Dá uma olhada no seu faces-config.xml e vê se o seu objeto do tipo UsuarioMB está mapeado para “usuario”

(odeio NullPointers, ele são tão genéricos… rsrs)

anderson.bonavides

Ta correto. Percebi também que quando vou debugar aparece algumas classes informando que não foi encontrada.
Esta é uma das classes não encontradada:

Class File Editor

Source not Found

The source atachament does not contain the source for file MethodBidingImpl.class

H

Cara…
Inicialize todos os atributos do seu ManagedBean, assim

private String nome = "";  
private String telefone = "";  
private String email = "";  
private String login = "";  
private String senha = "";  
private String tipo = "";

Veja se isso ajuda…

anderson.bonavides

Não deu certo.

:frowning:

Criado 6 de maio de 2008
Ultima resposta 6 de mai. de 2008
Respostas 8
Participantes 5