Bom dia, estou começando em JSF e estou lendo um livro chamado PROGRAMAÇÃO JAVA PARA WEB - da NOVATEC.
Estou em um exemplo onde monto um dataTable e tem um commandLink para Editar, Excluir e Ativar o usuario.
<h:dataTable value="#{usuarioBean.lista}" var="item" rules="rows" cellpadding="5" width="700" border="0">
<f:facet name="caption">
A listagem a seguir exibe a relação de toos os usuarios do sistema. Voce podera realizar ativação e desativação,edição e exclusão para os usuários.
</f:facet>
<f:facet name="header">Listagem de Usuários</f:facet>
<f:facet name="footer">Final da Lsitagem</f:facet>
<h:column>
<h:commandLink action="#{usuarioBean.ativar}">
<h:graphicImage library="img" name="usuario_ativo_#{item.ativo}.png" style="border:0"/>
<f:setPropertyActionListener target="#{usuarioBean.usuario}" value="#{usuario}"/>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">Código</f:facet>
<h:outputText value="#{item.codigo}"/>
</h:column>
<h:column>
<f:facet name="header">Idioma</f:facet>
<h:graphicImage library="img" name="#{item.idioma}.png"></h:graphicImage>
</h:column>
<h:column>
<f:facet name="header">Nome</f:facet>
<h:outputText value="#{item.nome}"/>
</h:column>
<h:column>
<f:facet name="header">Eemail</f:facet>
<a href="mailto:#{item.email}">#{item.email}"</a>
</h:column>
<h:column>
<f:facet name="header">Editar</f:facet>
<h:commandLink action="#{usuarioBean.editar}">
<h:graphicImage library="img" name="editar.png" style="border:0"/>
<f:setPropertyActionListener target="#{usuarioBean.usuario}" value="#{usuario}"/>
<f:setPropertyActionListener target="#{usuarioBean.destinoSalvar}" value="/admin/principal"></f:setPropertyActionListener>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">Excluir</f:facet>
<h:commandLink action="#{usuarioBean.excluir}">
<h:graphicImage library="img" name="lixo.png" style="border:0"/>
<f:setPropertyActionListener target="#{usuarioBean.usuario}" value="#{usuario}"/>
</h:commandLink>
</h:column>
</h:dataTable>
Estou preso mais precisamente no Ativar.
Parece que o setPropertyActionListener nao esta enviando o objeto para o MB.
classe ManagedBean
public class UsuarioBean
{
private Usuario usuario = new Usuario();
private List<Usuario> lista;
private String destinoSalvar;
private String confirma_senha;
public class UsuarioBean
{
private Usuario usuario = new Usuario();
private List<Usuario> lista;
private String destinoSalvar;
private String confirma_senha;
public String getDestinoSalvar() {
return destinoSalvar;
}
public void setDestinoSalvar(String destinoSalvar) {
this.destinoSalvar = destinoSalvar;
}
public Usuario getUsuario()
{
return usuario;
}
public void setUsuario(Usuario usuario)
{
this.usuario = usuario;
}
public String getConfirma_senha()
{
return confirma_senha;
}
public void setConfirma_senha(String confirma_senha)
{
this.confirma_senha = confirma_senha;
}
// cria uma nova instancia de usuario e seta o usuario como ativo
public String novo ()
{
this.destinoSalvar = "usuarioSucesso";
this.usuario = new Usuario();
this.usuario.setAtivo(true);
return "usuario";
}
public String salvar()
{
FacesContext contexto = FacesContext.getCurrentInstance();
String senha = this.usuario.getSenha();
if(!senha.equals(this.confirma_senha))// se as senhas nao baterem retorna null
{
FacesMessage mensagem =new FacesMessage("A senha não foi confirmada corretamente");
contexto.addMessage(null,mensagem);
return null;
}
UsuarioRN usuarioRN = new UsuarioRN();
usuarioRN.salvar(this.usuario);
return destinoSalvar;
}
public List<Usuario> getLista()
{
if(this.lista == null)
{
UsuarioRN usuarioRN = new UsuarioRN();
this.lista = usuarioRN.listar();
}
return lista;
}
public String ativar()
{
if(this.usuario.isAtivo())
{
this.usuario.setAtivo(false);
}else
{
this.usuario.setAtivo(true);
}
UsuarioRN usuarioRN = new UsuarioRN();
usuarioRN.salvar(usuario);
return null;
}
public String excluir()
{
UsuarioRN usuarioRN = new UsuarioRN();
usuarioRN.excluir(this.usuario);
this.lista = null;
return null; // pra ficar na mesma tela
}
public String editar()
{
this.confirma_senha = this.usuario.getSenha();
return "/public/usuario";
}
public void setLista(List<Usuario> lista)
{
this.lista = lista;
}
Esta dando o seguinte erro
usuario nulo21/04/2012 10:43:14 com.sun.faces.application.ActionListenerImpl processAction
SEVERE: java.lang.NullPointerException
javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:915)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
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:508)
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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at br.com.financeiroPessoal.web.UsuarioBean.ativar(UsuarioBean.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 21 more
21/04/2012 10:43:14 com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{usuarioBean.ativar}: java.lang.NullPointerException
javax.faces.FacesException: #{usuarioBean.ativar}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:915)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
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:508)
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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 20 more
Caused by: java.lang.NullPointerException
at br.com.financeiroPessoal.web.UsuarioBean.ativar(UsuarioBean.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 21 more
21/04/2012 10:43:14 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at br.com.financeiroPessoal.web.UsuarioBean.ativar(UsuarioBean.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:915)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
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:508)
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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Não sei se esta dando para entender.
Gostaria de uma luz, pois não estou conseguindo prosseguir.
Eu acho que o setPropertyActioListener nao esta enviando o objeto usuario para para p Bean.
Aguardo
Olhe a sua mensagem de erro: NullPointer at br.com.financeiroPessoal.web.UsuarioBean.ativar(UsuarioBean.java:96)
Você está com um NullPointer aí. O que tem nessa linha?
Me desculpe meu amigo, é que copiei o erro no eclipse e na hora de postar apaguei uns comentarios na classe Bean
Novamente a classe bean
Principal.xhtml
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:body>
<h1>Cadastro de Usuário</h1>
<h:form>
<h:messages/>
<h:dataTable value="#{usuarioBean.lista}" var="item" rules="rows" cellpadding="5" width="700" border="0">
<f:facet name="caption">
A listagem a seguir exibe a relação de toos os usuarios do sistema. Voce podera realizar ativação e desativação,edição e exclusão para os usuários.
</f:facet>
<f:facet name="header">Listagem de Usuários</f:facet>
<f:facet name="footer">Final da Lsitagem</f:facet>
<h:column>
<h:commandLink action="#{usuarioBean.ativar}">
<h:graphicImage library="img" name="usuario_ativo_#{item.ativo}.png" style="border:0"/>
<f:setPropertyActionListener target="#{usuarioBean.usuario}" value="#{usuario}"/>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">Código</f:facet>
<h:outputText value="#{item.codigo}"/>
</h:column>
<h:column>
<f:facet name="header">Idioma</f:facet>
<h:graphicImage library="img" name="#{item.idioma}.png"></h:graphicImage>
</h:column>
<h:column>
<f:facet name="header">Nome</f:facet>
<h:outputText value="#{item.nome}"/>
</h:column>
<h:column>
<f:facet name="header">Eemail</f:facet>
<a href="mailto:#{item.email}">#{item.email}"</a>
</h:column>
<h:column>
<f:facet name="header">Editar</f:facet>
<h:commandLink action="#{usuarioBean.editar}">
<h:graphicImage library="img" name="editar.png" style="border:0"/>
<f:setPropertyActionListener target="#{usuarioBean.usuario}" value="#{usuario}"/>
<f:setPropertyActionListener target="#{usuarioBean.destinoSalvar}" value="/admin/principal"></f:setPropertyActionListener>
</h:commandLink>
</h:column>
<h:column>
<f:facet name="header">Excluir</f:facet>
<h:commandLink action="#{usuarioBean.excluir}">
<h:graphicImage library="img" name="lixo.png" style="border:0"/>
<f:setPropertyActionListener target="#{usuarioBean.usuario}" value="#{usuario}"/>
</h:commandLink>
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
Bean
package br.com.financeiroPessoal.web;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import br.com.financeiroPessoal.usuario.Usuario;
import br.com.financeiroPessoal.usuario.UsuarioRN;
@ManagedBean
@RequestScoped
public class UsuarioBean
{
private Usuario usuario = new Usuario();
private List<Usuario> lista;
private String destinoSalvar;
private String confirma_senha;
public String getDestinoSalvar() {
return destinoSalvar;
}
public void setDestinoSalvar(String destinoSalvar) {
this.destinoSalvar = destinoSalvar;
}
public Usuario getUsuario()
{
return usuario;
}
public void setUsuario(Usuario usuario)
{
this.usuario = usuario;
}
public String getConfirma_senha()
{
return confirma_senha;
}
public void setConfirma_senha(String confirma_senha)
{
this.confirma_senha = confirma_senha;
}
// cria uma nova instancia de usuario e seta o usuario como ativo
public String novo ()
{
this.destinoSalvar = "usuarioSucesso";
this.usuario = new Usuario();
this.usuario.setAtivo(true);
return "usuario";
}
public String salvar()
{
FacesContext contexto = FacesContext.getCurrentInstance();
String senha = this.usuario.getSenha();
if(!senha.equals(this.confirma_senha))// se as senhas nao baterem retorna null
{
FacesMessage mensagem =new FacesMessage("A senha não foi confirmada corretamente");
contexto.addMessage(null,mensagem);
return null;
}
UsuarioRN usuarioRN = new UsuarioRN();
usuarioRN.salvar(this.usuario);
return destinoSalvar;
}
public List<Usuario> getLista()
{
if(this.lista == null)
{
UsuarioRN usuarioRN = new UsuarioRN();
this.lista = usuarioRN.listar();
}
return lista;
}
public String ativar()
{
if(usuario == null)
{
System.out.print("usuario nulo");
}else
{
System.out.print("usuario nao nulo");
}
if(this.usuario.isAtivo())
{
this.usuario.setAtivo(false);
}else
{
this.usuario.setAtivo(true);
}
UsuarioRN usuarioRN = new UsuarioRN();
usuarioRN.salvar(usuario);
return null;
}
public String excluir()
{
UsuarioRN usuarioRN = new UsuarioRN();
usuarioRN.excluir(this.usuario);
this.lista = null;
return null; // pra ficar na mesma tela
}
public String editar()
{
this.confirma_senha = this.usuario.getSenha();
return "/public/usuario";
}
public void setLista(List<Usuario> lista)
{
this.lista = lista;
}
}
Erro
usuario nulo21/04/2012 11:51:07 com.sun.faces.application.ActionListenerImpl processAction
SEVERE: java.lang.NullPointerException
javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:915)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
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:508)
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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at br.com.financeiroPessoal.web.UsuarioBean.ativar(UsuarioBean.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 21 more
21/04/2012 11:51:07 com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{usuarioBean.ativar}: java.lang.NullPointerException
javax.faces.FacesException: #{usuarioBean.ativar}: java.lang.NullPointerException
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:915)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
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:508)
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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 20 more
Caused by: java.lang.NullPointerException
at br.com.financeiroPessoal.web.UsuarioBean.ativar(UsuarioBean.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 21 more
21/04/2012 11:51:07 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at br.com.financeiroPessoal.web.UsuarioBean.ativar(UsuarioBean.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.el.parser.AstValue.invoke(AstValue.java:131)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:915)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
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:508)
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:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
O nullpointer é na linha 96, quando eu verifico se o usuario esta ativo ou nao.
Por isso eu estou achando que o setPropertyActionListener nao esta enviando o objeto usuario para o bean.
Obrigado e aguardo uma luz por favor!!!
No livro que você está utilizando, ele realmente deixa o MB como request scope?
Faz um teste, troca para session e testa.
Outra coisa, no seu get faça:[code]public Usuario getUsuario(){
if (usuario == null){
usuario = new Usuario();
}
return usuario;
}[/code]
No livro esta @RequestScoped sim.
Troquei para @SessionScoped e fiz a verificação no metodo getUsusario mas nao mudou nada.
Ainda da nullpointer na hora de verificar se o ususario esta ativo ou nao.
O que pode ser isso?
Sera que o setPropertyActionListener esta funcionando?
Eu estava lendo sobre, e vi que pode ser usado a tag param.
como eu usaria essa tag no meu exemplo?
Obrigado
Já descobri o que esta acontecendo.
na declaracao da dataTable eu coloque
<h:dataTable value="#{usuarioBean.lista}" var="item" rules="rows" cellpadding="5" width="700" border="0">
o objeto usuario e retornado pelo identificador item
<h:column>
<h:commandLink action="#{usuarioBean.ativar}">
<h:graphicImage library="img" name="usuario_ativo_#{item.ativo}.png" style="border:0"/>
<f:setPropertyActionListener target="#{usuarioBean.usuario}" value="#{item}"/>
</h:commandLink>
</h:column>
no setPropertyActionListener eu tenho que colocar item e nao usuario, porque no livro o autor colocou em var=“usuario” e eu coloquei item.
Muito obrigado pela sua ajuda.
Vou fazer algumas correções e testes.
Se acontecer problemas eu aviso.
muito obrigado mesmo jakefrog, voce esta sempre me ajudando, continue assim.
bom feriado.