Data valor now definido!

Tenho um campo chamado data do cadastro, queria que esse valor foce preenchido pela da corrente, na hora do cadastro do usuario ! alguém sabe fazer isso e como se faz ? valeu

Date dataGravacao;

dataGravacao = new Date();

E boa !

Complementando:

A recuperação da data atual só funciona no java.util.Date.

java.sql.Date não recupera a data atual na construção do objeto.

:wink:

natureza E adrianoandrade Obrigado pela ajuda !

   1. Date dataGravacao;  
   2.   
   3. dataGravacao = new Date();  

Esse código eu faço onde na lógica ?


package br.com.serjaum.mb;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.serjaum.facade.ClientefFacade;
import br.com.serjaum.facade.ClientefFacadeImpl;
import br.com.serjaum.modelo.Clientef;

public class ClientefMB implements Serializable {

	private static long serialVersionUID = -333995781063775201L;

              /**
               * @return the serialVersionUID
               */
              public static long getSerialVersionUID() {
                            return serialVersionUID;
              }

              /**
               * @param aSerialVersionUID the serialVersionUID to set
               */
              public static void setSerialVersionUID(long aSerialVersionUID) {
                            serialVersionUID = aSerialVersionUID;
              }

	private Clientef Clientef = new Clientef();

	private Long id;

	public ClientefMB(){
		System.out.println(" >>>>>>>>>>>>>>>>>>>> Contrutor do CLIENTEF_MB <<<<<<<<<<<<<<<<<<");

		if(this.Clientef == null){
			this.Clientef = new Clientef();
		}
	}

public String login() throws Exception{
        boolean logado = true;


        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        HttpServletResponse rp = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        HttpServletRequest rq = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        ClientefFacade ClientefService = new ClientefFacadeImpl();

       // logado = ClientefService.autentica(this.getClientef().getEmail(), this.getClientef().getSenha(),this.getClientef().getStatus());

        if(logado){
            session.setAttribute("user", logado);
            rp.sendRedirect(rq.getContextPath() + "/pages/index.jsf");
            return "success";

        }else{

            session.setAttribute("user", null);
            session.removeAttribute("user");
            rp.sendRedirect(rq.getContextPath() + "/pages/login/login.jsf");
            return "failure";
        }


        }


	public String logout() {
		HttpServletRequest rq = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
		HttpServletResponse rp = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
		FacesContext facesContext = FacesContext.getCurrentInstance();
		HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
		session.invalidate();
		try {
			rp.sendRedirect(rq.getContextPath() + "/pages/login/login.jsf");
		} catch (IOException e) {
			e.printStackTrace();
		}

		return "logoutOk";
	}


*******************************************************  assim ?
 Date dataGravacao;  
 dataGravacao = new Date();  
********************************************************

	public String save(){
		ClientefFacade ClientefService = new ClientefFacadeImpl();
		ClientefService.salva(this.getClientef());
	        this.setClientef(new Clientef());
		return "cadastraSucesso";
	}

	public String delete(){
		ClientefFacade ClientefService = new ClientefFacadeImpl();
		        this.getClientef().setId(getId());
		ClientefService.remove(this.getClientef());
		        this.setClientef(new Clientef());

		return "removeSucesso";
	}

	public String merge(){
		ClientefFacade ClientefService = new ClientefFacadeImpl();
		ClientefService.atualiza(this.getClientef());
		        this.setClientef(new Clientef());

		return "atualizaSucesso";
	}

	public String load(){
		ClientefFacade ClientefService = new ClientefFacadeImpl();
		        this.setClientef(ClientefService.procura(this.getId()));

		return "pesquisaSucesso";
	}

	public String pesquisaByNome(){
		ClientefFacadeImpl ClientefService = new ClientefFacadeImpl();
		        this.setClientef(ClientefService.procuraByNome(this.getClientef().getNome()));

		return "pesquisaByNomeSucesso";
	}

	public List<Clientef> getClientefs(){
		ClientefFacade ClientefService = new ClientefFacadeImpl();

		return ClientefService.lista();
	}

	public List<Clientef> getClientefsByNome(){
		ClientefFacade ClientefService = new ClientefFacadeImpl();// plura por causa da tabela

		List<Clientef> lista = ClientefService.pesquisaClientefsByNome(this.getClientef().getNome());

		return lista;
	}

	public Clientef getClientef() {
		return Clientef;
	}

	public void setClientef(Clientef Clientef) {
		this.Clientef = Clientef;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

}

Bom a data vai ser gravada na sua entidade então sendo assim, faça a declaração dela lá.

E ai onde você for gravar, ou atualizar que tiver que inserir esta data no bd você seta a data com a data atual pelo comando que te passei.

natureza ! da um erro não deixa nem compilar !

minha entidade ta assim :

package br.com.serjaum.modelo;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="clientef")
public class Clientef implements Serializable {

    @Temporal(javax.persistence.TemporalType.DATE)


private static long serialVersionUID = 2174678509151116408L;

              /**
               * @return the serialVersionUID
               */
              public static long getSerialVersionUID() {
                            return serialVersionUID;
              }

              /**
               * @param aSerialVersionUID the serialVersionUID to set
               */
              public static void setSerialVersionUID(long aSerialVersionUID) {
                            serialVersionUID = aSerialVersionUID;
              }
              @Id
	      @GeneratedValue(strategy=GenerationType.IDENTITY)
	      @Column(name="clientef_id")
	      private Long id;

              @Column(name="nome")
              private String   nome;

              @Column(name="cpf")
              private String cpf;

              @Column(name="naci")
              @Temporal(TemporalType.DATE)
              private Date   datanacimento;

              @Column(name="uf_nas")
              private String   uf_nas;

              @Column(name="naturalidade")
              private String   naturalidade;

              @Column(name="tipo_doc_ide")
              private String   tipo_doc_ide;

              @Column(name="numero_doc")
              private Long   numero_doc;

              @Column(name="orgao_emi")
              private String   orgao_emi;

              private String   uf_emis;
              @Column(name="ufemissao")

              @Temporal(TemporalType.DATE)
              private Date   data_emi;
              @Column(name="data_emi")

              @Temporal(TemporalType.DATE)
              private Date   data_ven_doc;
              @Column(name="data_ven_doc")

              private String   endereco;
              @Column(name="endereco")

              private String   cep;
              @Column(name="cep")

              private String   bairro;
              @Column(name="bairro")

              private String   cidade;
              @Column(name="cidade")

              private String   uf_end;
              @Column(name="uf_end")

              private String   estado_civ;
              @Column(name="estado_civ")

              private String   email_clientef;
              @Column(name="email_clientef")

              private String   telefone_clientef;
              @Column(name="telefone_clientef")

              @Temporal(TemporalType.DATE)
              private Date   data_cad ;
              @Column(name="data_cad")


              private String   perfil_clientef;
              @Column(name="perfil_clientef")

              private String   status_clientef;


              

       
        @Override
	public boolean equals(Object obj){
		if( (obj instanceof Clientef) && ( ((Clientef)obj).getCpf().equals(this.getCpf())) ){
			return true;
		}else{
			return false;
		}
	}

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + (this.getId() != null ? this.getId().hashCode() : 0);
        hash = 23 * hash + (this.getNome() != null ? this.getNome().hashCode() : 0);
        hash = 23 * hash + (this.getCpf() != null ? this.getCpf().hashCode() : 0);
        hash = 23 * hash + (this.getDatanacimento() != null ? this.getDatanacimento().hashCode() : 0);
        hash = 23 * hash + (this.getUf_nas() != null ? this.getUf_nas().hashCode() : 0);
        hash = 23 * hash + (this.getNaturalidade() != null ? this.getNaturalidade().hashCode() : 0);
        hash = 23 * hash + (this.getTipo_doc_ide() != null ? this.getTipo_doc_ide().hashCode() : 0);
        hash = 23 * hash + (this.getNumero_doc() != null ? this.getNumero_doc().hashCode() : 0);
        hash = 23 * hash + (this.getOrgao_emi() != null ? this.getOrgao_emi().hashCode() : 0);
        hash = 23 * hash + (this.getUf_emis() != null ? this.getUf_emis().hashCode() : 0);
        hash = 23 * hash + (this.getData_emi() != null ? this.getData_emi().hashCode() : 0);
        hash = 23 * hash + (this.getData_ven_doc() != null ? this.getData_ven_doc().hashCode() : 0);
        hash = 23 * hash + (this.getEndereco() != null ? this.getEndereco().hashCode() : 0);
        hash = 23 * hash + (this.getCep() != null ? this.getCep().hashCode() : 0);
        hash = 23 * hash + (this.getBairro() != null ? this.getBairro().hashCode() : 0);
        hash = 23 * hash + (this.getCidade() != null ? this.getCidade().hashCode() : 0);
        hash = 23 * hash + (this.getUf_end() != null ? this.getUf_end().hashCode() : 0);
        hash = 23 * hash + (this.getEstado_civ() != null ? this.getEstado_civ().hashCode() : 0);
        hash = 23 * hash + (this.getEmail_clientef() != null ? this.getEmail_clientef().hashCode() : 0);
        hash = 23 * hash + (this.getTelefone_clientef() != null ? this.getTelefone_clientef().hashCode() : 0);
        hash = 23 * hash + (this.getData_cad() != null ? this.getData_cad().hashCode() : 0);
        hash = 23 * hash + (this.getPerfil_clientef() != null ? this.getPerfil_clientef().hashCode() : 0);
        hash = 23 * hash + (this.getStatus_clientef() != null ? this.getStatus_clientef().hashCode() : 0);
        return hash;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the nome
     */
    public String getNome() {
        return nome;
    }

    /**
     * @param nome the nome to set
     */
    public void setNome(String nome) {
        this.nome = nome;
    }

    /**
     * @return the cpf
     */
    public String getCpf() {
        return cpf;
    }

    /**
     * @param cpf the cpf to set
     */
    public void setCpf(String cpf) {
        this.cpf = cpf;
    }

    /**
     * @return the datanacimento
     */
    public Date getDatanacimento() {
        return datanacimento;
    }

    /**
     * @param datanacimento the datanacimento to set
     */
    public void setDatanacimento(Date datanacimento) {
        this.datanacimento = datanacimento;
    }

    /**
     * @return the uf_nas
     */
    public String getUf_nas() {
        return uf_nas;
    }

    /**
     * @param uf_nas the uf_nas to set
     */
    public void setUf_nas(String uf_nas) {
        this.uf_nas = uf_nas;
    }

    /**
     * @return the naturalidade
     */
    public String getNaturalidade() {
        return naturalidade;
    }

    /**
     * @param naturalidade the naturalidade to set
     */
    public void setNaturalidade(String naturalidade) {
        this.naturalidade = naturalidade;
    }

    /**
     * @return the tipo_doc_ide
     */
    public String getTipo_doc_ide() {
        return tipo_doc_ide;
    }

    /**
     * @param tipo_doc_ide the tipo_doc_ide to set
     */
    public void setTipo_doc_ide(String tipo_doc_ide) {
        this.tipo_doc_ide = tipo_doc_ide;
    }

    /**
     * @return the numero_doc
     */
    public Long getNumero_doc() {
        return numero_doc;
    }

    /**
     * @param numero_doc the numero_doc to set
     */
    public void setNumero_doc(Long numero_doc) {
        this.numero_doc = numero_doc;
    }

    /**
     * @return the orgao_emi
     */
    public String getOrgao_emi() {
        return orgao_emi;
    }

    /**
     * @param orgao_emi the orgao_emi to set
     */
    public void setOrgao_emi(String orgao_emi) {
        this.orgao_emi = orgao_emi;
    }

    /**
     * @return the uf_emis
     */
    public String getUf_emis() {
        return uf_emis;
    }

    /**
     * @param uf_emis the uf_emis to set
     */
    public void setUf_emis(String uf_emis) {
        this.uf_emis = uf_emis;
    }

    /**
     * @return the data_emi
     */
    public Date getData_emi() {
        return data_emi;
    }

    /**
     * @param data_emi the data_emi to set
     */
    public void setData_emi(Date data_emi) {
        this.data_emi = data_emi;
    }

    /**
     * @return the data_ven_doc
     */
    public Date getData_ven_doc() {
        return data_ven_doc;
    }

    /**
     * @param data_ven_doc the data_ven_doc to set
     */
    public void setData_ven_doc(Date data_ven_doc) {
        this.data_ven_doc = data_ven_doc;
    }

    /**
     * @return the endereco
     */
    public String getEndereco() {
        return endereco;
    }

    /**
     * @param endereco the endereco to set
     */
    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    /**
     * @return the cep
     */
    public String getCep() {
        return cep;
    }

    /**
     * @param cep the cep to set
     */
    public void setCep(String cep) {
        this.cep = cep;
    }

    /**
     * @return the bairro
     */
    public String getBairro() {
        return bairro;
    }

    /**
     * @param bairro the bairro to set
     */
    public void setBairro(String bairro) {
        this.bairro = bairro;
    }

    /**
     * @return the cidade
     */
    public String getCidade() {
        return cidade;
    }

    /**
     * @param cidade the cidade to set
     */
    public void setCidade(String cidade) {
        this.cidade = cidade;
    }

    /**
     * @return the uf_end
     */
    public String getUf_end() {
        return uf_end;
    }

    /**
     * @param uf_end the uf_end to set
     */
    public void setUf_end(String uf_end) {
        this.uf_end = uf_end;
    }

    /**
     * @return the estado_civ
     */
    public String getEstado_civ() {
        return estado_civ;
    }

    /**
     * @param estado_civ the estado_civ to set
     */
    public void setEstado_civ(String estado_civ) {
        this.estado_civ = estado_civ;
    }

    /**
     * @return the email_clientef
     */
    public String getEmail_clientef() {
        return email_clientef;
    }

    /**
     * @param email_clientef the email_clientef to set
     */
    public void setEmail_clientef(String email_clientef) {
        this.email_clientef = email_clientef;
    }

    /**
     * @return the telefone_clientef
     */
    public String getTelefone_clientef() {
        return telefone_clientef;
    }

    /**
     * @param telefone_clientef the telefone_clientef to set
     */
    public void setTelefone_clientef(String telefone_clientef) {
        this.telefone_clientef = telefone_clientef;
    }

    /**
     * @return the data_cad
     */
    public Date getData_cad() {
        return data_cad;
    }

    /**
     * @param data_cad the data_cad to set
     */
    public void setData_cad(Date data_cad) {
        this.data_cad = data_cad;
    }

    /**
     * @return the perfil_clientef
     */
    public String getPerfil_clientef() {
        return perfil_clientef;
    }

    /**
     * @param perfil_clientef the perfil_clientef to set
     */
    public void setPerfil_clientef(String perfil_clientef) {
        this.perfil_clientef = perfil_clientef;
    }

    /**
     * @return the status_clientef
     */
    public String getStatus_clientef() {
        return status_clientef;
    }

    /**
     * @param status_clientef the status_clientef to set
     */
    public void setStatus_clientef(String status_clientef) {
        this.status_clientef = status_clientef;
    }

   

}