olá pessoal!
estou desenvolvendo um sistema, mas quando desejo alterar dados na tabela de clientes é mostrado o seguinte erro:
Error calling action method of component with id altexDadosCliente:alterarCliente
Caused by:
org.hibernate.TransientObjectException - The given object has a null identifier: br.com.ses.modelo.bean.Cliente
segue abaixo a classe Cliente.java
package br.com.ses.modelo.bean;
import java.util.List;
import java.util.Date;
public class Cliente {
private Integer codigo;
private String nome;
private String endereco;
private String complemento;
private String bairro;
private String cidade;
private String uf;
private String cep;
private Date datanasc;
private Date desde;
private String rg;
private String cpf;
private String cnpj;
private String insest;
private String foneres;
private String fonecom;
private String fax;
private String celular;
private String contato;
private String observacao;
private List<Produto> produtos;
public Integer getCodigo() {
return codigo;
}
public void setCodigo(Integer codigo) {
this.codigo = codigo;
}
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 getComplemento() {
return complemento;
}
public void setComplemento(String complemento) {
this.complemento = complemento;
}
public String getBairro() {
return bairro;
}
public void setBairro(String bairro) {
this.bairro = bairro;
}
public String getCidade() {
return cidade;
}
public void setCidade(String cidade) {
this.cidade = cidade;
}
public String getUf() {
return uf;
}
public void setUf(String uf) {
this.uf = uf;
}
public String getCep() {
return cep;
}
public void setCep(String cep) {
this.cep = cep;
}
public Date getDatanasc() {
return datanasc;
}
public void setDatanasc(Date datanasc) {
this.datanasc = datanasc;
}
public Date getDesde() {
return desde;
}
public void setDesde(Date desde) {
this.desde = desde;
}
public String getRg() {
return rg;
}
public void setRg(String rg) {
this.rg = rg;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getCnpj() {
return cnpj;
}
public void setCnpj(String cnpj) {
this.cnpj = cnpj;
}
public String getInsest() {
return insest;
}
public void setInsest(String insest) {
this.insest = insest;
}
public String getFoneres() {
return foneres;
}
public void setFoneres(String foneres) {
this.foneres = foneres;
}
public String getFonecom() {
return fonecom;
}
public void setFonecom(String fonecom) {
this.fonecom = fonecom;
}
public String getFax() {
return fax;
}
public void setFax(String fax) {
this.fax = fax;
}
public String getCelular() {
return celular;
}
public void setCelular(String celular) {
this.celular = celular;
}
public String getContato() {
return contato;
}
public void setContato(String contato) {
this.contato = contato;
}
public String getObservacao() {
return observacao;
}
public void setObservacao(String observacao) {
this.observacao = observacao;
}
public List<Produto> getProdutos() {
return produtos;
}
public void setProdutos(List<Produto> produtos) {
this.produtos = produtos;
}
}
abaixo a classe de bean controle:
package br.com.ses.controle;
import java.util.HashSet;
import javax.faces.event.ActionEvent;
import br.com.ses.modelo.bean.CNF;
import br.com.ses.modelo.bean.Cliente;
import br.com.ses.modelo.bean.DNF;
import br.com.ses.modelo.dao.HibernateDAO;
import br.com.ses.modelo.dao.InterfaceDAO;
import br.com.ses.util.FacesContextUtil;
public class ClienteBean {
private CNF cnf = new CNF();
private String codigoCliente;
private Cliente cliente = new Cliente();
private Cliente cliSucesso;
public String alteraCliente(){
InterfaceDAO<Cliente> clienteDAO = new HibernateDAO<Cliente>(Cliente.class, FacesContextUtil.getRequestSession());
Cliente bean = null;
clienteDAO.atualizar(cliente);
return "altClisucesso";
}
public String alteraExcluiCliente(){
return "altexCliente";
}
public String incluirCliente(){
if(cliente.getDatanasc() == null || cliente.getDesde() == null){
FacesContextUtil.setMensagemErro("Preencha a data de nascimento/desde!");
return null;
}else if(cliente.getDatanasc().getTime() > cliente.getDesde().getTime()){
FacesContextUtil.setMensagemErro("A data de nascimento não pode posterior a data cliente desde!");
return null;
}
InterfaceDAO<Cliente> clienteDAO = new HibernateDAO<Cliente>(Cliente.class, FacesContextUtil.getRequestSession());
clienteDAO.salvar(getCliente());
this.cliSucesso = clienteDAO.getBean(getCliente().getCodigo());
limparCliente();
return "sucesso";
}
public CNF getCnf() {
return cnf;
}
public String getCodigoCliente() {
return codigoCliente;
}
public void setCodigoCliente(String codigoCliente) {
//System.out.println(">>>clienteBean.setcodigoCliente");
this.codigoCliente = codigoCliente;
}
public String confirmarCliente(){
//System.out.println(">>>Confirmar Cliente");
this.cnf = new CNF();
InterfaceDAO<Cliente> clienteDAO = new HibernateDAO<Cliente>(Cliente.class, FacesContextUtil.getRequestSession());
this.cnf.setCliente(clienteDAO.getBean(Integer.valueOf(codigoCliente)));
this.cnf.setDetalheNF(new HashSet<DNF>());
//System.out.println(">>>Cliente Selecionado: "+cnf.getCliente().getCodigo());
return null;
}//fim do metodo confirmar cliente
public void alterarCliente(ActionEvent evt){
limparCliente();
}//fim do metodo alterarCliente
private void limparCliente(){
this.codigoCliente = null;
this.cnf = new CNF();
setCliente(new Cliente());
}
public Cliente getCliente() {
return cliente;
}
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
public Cliente getCliSucesso() {
return cliSucesso;
}
}//fim da classe
Abaixo arquivo cliente.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"%>
<%@ taglib prefix="htm" uri="http://jsftutorials.net/htmLib"%>
<%@ taglib prefix="tr" uri="http://myfaces.apache.org/trinidad"%>
<%@ taglib prefix="trh" uri="http://myfaces.apache.org/trinidad/html"%>
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cadastro de Clientes</title>
<link rel="stylesheet" href="css/principal.css" type="text/css" />
</head>
<body>
<f:view>
<htm:div id="mensagens" rendered="#{not empty facesContext.maximumSeverity}">
<h:panelGrid id="painelMensagens" columns="2">
<h:graphicImage value="images/delete-comment-red.gif" title="Erro"></h:graphicImage>
<h:messages></h:messages>
</h:panelGrid>
</htm:div><!-- mensagens -->
<htm:div id="divPrincipal" styleClass="corpoPrincipal">
<h1>S&S Serviços e Estoque Cliente</h1>
<htm:div id="divcorpoEsquerda" styleClass="corpoEsquerda">
<htm:fieldset style="borda">
<htm:legend style="legenda">Clientes:</htm:legend>
<h:form id="formCliente">
<tr:subform>
<h:panelGrid columns="2" styleClass="panelGrid" columnClasses="colunaDireita, colunaEsquerda">
<h:outputText value="Cliente->" styleClass="labelInput"></h:outputText>
<h:selectOneMenu id="selectCliente" value="#{clienteBean.codigoCliente}"
disabled="#{not empty clienteBean.cnf.cliente}" required="true" requiredMessage="Selecione um Cliente!">
<f:selectItems value="#{clienteBBean.clientes}"/>
</h:selectOneMenu>
<h:panelGroup></h:panelGroup>
<h:panelGroup>
<h:commandButton id="confirmarCliente" value="Confirmar" action="#{clienteBean.confirmarCliente}" styleClass="panelBotaoConfirmar">
</h:commandButton>
<h:commandButton id="alterarCliente" value="Novo/Alterar" actionListener="#{clienteBean.alterarCliente}" styleClass="panelBotaoEditar">
</h:commandButton>
</h:panelGroup><!-- confirmar/alterar -->
</h:panelGrid><!-- panelGrid cabeçalho -->
</tr:subform>
<h:panelGrid columns="1" styleClass="panelGrid" rendered="#{empty clienteBean.cnf.cliente}">
<h:panelGrid columns="2" width="100%" columnClasses="colunaDireita, colunaEsquerda">
<h:outputText value="Nome:" styleClass="labelInput"></h:outputText>
<h:inputText id="inputNomeCliente" value="#{clienteBBean.cliente.nome}"
converter="stringNull" ></h:inputText>
<h:outputText value="CPF:" styleClass="labelInput"></h:outputText>
<h:inputText id="inputCpfCliente" value="#{clienteBBean.cliente.cpf}"
converter="stringNull" ></h:inputText>
<h:outputText value="CNPJ:" styleClass="labelInput"></h:outputText>
<h:inputText id="inputCnpjCliente" value="#{clienteBBean.cliente.cnpj}"
converter="stringNull" ></h:inputText>
</h:panelGrid><!-- panelGrid consultacoluna -->
<h:commandButton id="consultarCliente" value="Consultar" styleClass="panelBotaoConsultar"></h:commandButton>
</h:panelGrid><!-- panelGrid consulta -->
</h:form><!-- formCliente -->
</htm:fieldset><!-- fieldset borda -->
</htm:div><!-- divcorpoEsquerda -->
<htm:div id="divcorpoDireita" styleClass="corpoDireita">
<htm:div id="previewCliente" styleClass="previewNotaFiscal" rendered="#{not empty clienteBean.cnf.cliente}">
<t:div id="nrNF">
<h:outputText styleClass="inputNrNF" value="Dados do Cliente:" />
<htm:small style="font-size:10px;"></htm:small>
</t:div><!-- nrNF -->
<h:form id="dadosCliente">
<htm:div id="dadosCliente">
<htm:p>Codigo:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.codigo}" /></htm:big>
<htm:p>Nome/Razão Social:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.nome}" /></htm:big>
<htm:p>Endereço:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.endereco}" /></htm:big>
<htm:p>Complemento:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.complemento}" /></htm:big>
<htm:p>Bairro:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.bairro}" /></htm:big>
<htm:p>Cidade:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.cidade}" /></htm:big>
<htm:p>Uf:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.uf}" /></htm:big>
<htm:p>Cep:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.cep}" /></htm:big>
<htm:p>Data de Nascimento:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.datanasc}" /></htm:big>
<htm:p>Cliente Desde:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.desde}" /></htm:big>
<htm:p>Rg:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.rg}" /></htm:big>
<htm:p>CPF:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.cpf}" /></htm:big>
<htm:p>CNPJ:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.cnpj}" /></htm:big>
<htm:p>Inscrição Estadual:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.insest}" /></htm:big>
<htm:p>Fone Residencial:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.foneres}" /></htm:big>
<htm:p>Fone Comercial:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.fonecom}" /></htm:big>
<htm:p>Fax:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.fax}" /></htm:big>
<htm:p>Celular:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.celular}" /></htm:big>
<htm:p>Contato</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.contato}" /></htm:big>
<htm:p>Observações</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.observacao}" /></htm:big>
</htm:div><!-- dadosCliente -->
<h:commandButton id="alterarExcluirCliente" value="Excluir/Alterar" styleClass="panelBotaoEditar"
action="#{clienteBean.alteraExcluiCliente}"
onclick="return confirm('Deseja relamente alterar ou excluir o Cliente?');">
</h:commandButton>
</h:form><!-- dadosClientes -->
</htm:div><!-- previewCliente -->
</htm:div><!-- divcorpoDireita -->
<htm:div id="divcadcorpoDireita" styleClass="corpoDireita">
<htm:div id="previewCadCliente" styleClass="previewNotaFiscal" rendered="#{empty clienteBean.cnf.cliente}">
<t:div id="cadnrNF">
<h:outputText styleClass="cabecalho" value="Cadastrar Cliente"/>
<htm:small style="font-size:10px;"></htm:small>
</t:div><!-- cadnrNF -->
<h:form id="dadosCadCliente">
<htm:div id="dadosCadCliente">
<htm:p>Nome/Razão Social:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.nome}" /></htm:big>
<htm:p>Endereço:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.endereco}" /></htm:big>
<htm:p>Complemento:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.complemento}" /></htm:big>
<htm:p>Bairro:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.bairro}" /></htm:big>
<htm:p>Cidade:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.cidade}" /></htm:big>
<htm:p>Uf:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.uf}" /></htm:big>
<htm:p>Cep:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.cep}" /></htm:big>
<t:div id="calendario" forceId="true">
<htm:p>
<h:outputText value="Data de Nascimento:" />
<t:inputCalendar value="#{clienteBean.cliente.datanasc}" renderAsPopup="true"
renderPopupButtonAsImage="true" popupButtonImageUrl="images/search-blue.gif">
</t:inputCalendar>
</htm:p>
<htm:p>
<h:outputText value="Cliente Desde:" />
<t:inputCalendar value="#{clienteBean.cliente.desde}" renderAsPopup="true"
renderPopupButtonAsImage="true" popupButtonImageUrl="images/search-blue.gif">
</t:inputCalendar>
</htm:p>
</t:div><!-- calendario -->
<htm:p>Rg:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.rg}" /></htm:big>
<htm:p>CPF:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.cpf}" /></htm:big>
<htm:p>CNPJ:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.cnpj}" /></htm:big>
<htm:p>Inscrição Estadual:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.insest}" /></htm:big>
<htm:p>Fone Residencial:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.foneres}" /></htm:big>
<htm:p>Fone Comercial:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.fonecom}" /></htm:big>
<htm:p>Fax:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.fax}" /></htm:big>
<htm:p>Celular:</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.celular}" /></htm:big>
<htm:p>Contato</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.contato}" /></htm:big>
<htm:p>Observações</htm:p><htm:big><h:inputText value="#{clienteBean.cliente.observacao}" /></htm:big>
</htm:div><!-- dadosCadCliente -->
<h:commandButton styleClass="panelBotaoConfirmar" value="Incluir Cliente"
action="#{clienteBean.incluirCliente}"
onclick="return confirm('Confirma a inclusão do Cliente?');">
</h:commandButton>
</h:form><!-- dadosCadClientes -->
</htm:div><!-- previewCadCliente -->
</htm:div><!-- divcadcorpoDireita -->
</htm:div><!-- divPrincipal -->
</f:view>
</body>
</html>
Arquivo clientealteraexclui.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"%>
<%@ taglib prefix="htm" uri="http://jsftutorials.net/htmLib"%>
<%@ taglib prefix="tr" uri="http://myfaces.apache.org/trinidad"%>
<%@ taglib prefix="trh" uri="http://myfaces.apache.org/trinidad/html"%>
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Alterar/Ecluir Dados do Clientes</title>
<link rel="stylesheet" href="css/principal.css" type="text/css" />
</head>
<body>
<f:view>
<htm:div id="mensagens" rendered="#{not empty facesContext.maximumSeverity}">
<h:panelGrid id="painelMensagens" columns="2">
<h:graphicImage value="images/delete-comment-red.gif" title="Erro"></h:graphicImage>
<h:messages></h:messages>
</h:panelGrid>
</htm:div><!-- mensagens -->
<htm:div id="divPrincipal" styleClass="corpoPrincipal">
<h1>S&S Serviços e Estoque Cliente</h1>
<htm:div id="divcorpoDireita" styleClass="corpoDireita">
<htm:div id="previewCliente" styleClass="previewNotaFiscal">
<t:div id="nrNF">
<h:outputText styleClass="inputNrNF" value="Alterar ou Excluir Dados do Cliente!" />
<htm:small style="font-size:10px;"></htm:small>
</t:div><!-- nrNF -->
<h:form id="altexDadosCliente">
<htm:div id="dadosCliente">
<htm:p>Codigo:</htm:p><htm:big><h:outputText value="#{clienteBean.cnf.cliente.codigo}" /></htm:big>
<htm:p>Nome/Razão Social:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.nome}" /></htm:big>
<htm:p>Endereço:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.endereco}" /></htm:big>
<htm:p>Complemento:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.complemento}" /></htm:big>
<htm:p>Bairro:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.bairro}" /></htm:big>
<htm:p>Cidade:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.cidade}" /></htm:big>
<htm:p>Uf:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.uf}" /></htm:big>
<htm:p>Cep:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.cep}" /></htm:big>
<htm:p>Data de Nascimento:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.datanasc}" /></htm:big>
<htm:p>Cliente Desde:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.desde}" /></htm:big>
<htm:p>Rg:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.rg}" /></htm:big>
<htm:p>CPF:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.cpf}" /></htm:big>
<htm:p>CNPJ:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.cnpj}" /></htm:big>
<htm:p>Inscrição Estadual:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.insest}" /></htm:big>
<htm:p>Fone Residencial:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.foneres}" /></htm:big>
<htm:p>Fone Comercial:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.fonecom}" /></htm:big>
<htm:p>Fax:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.fax}" /></htm:big>
<htm:p>Celular:</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.celular}" /></htm:big>
<htm:p>Contato</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.contato}" /></htm:big>
<htm:p>Observações</htm:p><htm:big><h:inputText value="#{clienteBean.cnf.cliente.observacao}" /></htm:big>
</htm:div><!-- dadosCliente -->
<h:commandButton id="alterarCliente" value="Alterar" action="#{clienteBean.alteraCliente}" styleClass="panelBotaoEditar"
onclick="return confirm('Deseja Alterar os Dados do Cliente?');">
</h:commandButton>
<h:commandButton id="excluirCliente" value="Excluir" actionListener="#{clienteBean.alterarCliente}" styleClass="panelBotaoSubtrair"
onclick="return confirm('Deseja Realmente Excluir este Cliente?');">
</h:commandButton>
</h:form><!-- altexDadosClientes -->
</htm:div><!-- previewCliente -->
</htm:div><!-- divcorpoDireita -->
</htm:div><!-- divPrincipal -->
</f:view>
</body>
</html>
arquivo faces-config.xml:
<navigation-rule>
<from-view-id>/cliente.jsp</from-view-id>
<navigation-case>
<from-outcome>sucesso</from-outcome>
<to-view-id>/clientesucesso.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>altexCliente</from-outcome>
<to-view-id>/clientealteraexclui.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/clientealteraexclui.jsp</from-view-id>
<navigation-case>
<from-outcome>altClisucesso</from-outcome>
<to-view-id>clientealterado.jsp</to-view-id>
</navigation-case>
</navigation-rule>
alguem pode solucionar este problema?