segue minha tela:
[code]
<ui:composition template="/template.xhtml">
<ui:define name="principal">
<h:messages />
<h:form>
<h:panelGrid columns="2">
<f:facet name="header">
<h:outputText value="FORMULARIO DE CADASTRO" />
</f:facet>
<h:outputLabel value="Nome: " />
<h:inputText value="#{contato.contato.nome}" />
<h:outputLabel value="Data de Nascimento: " />
<h:inputText value="#{contato.contato.dataNascimento}">
<f:convertDateTime pattern="dd/MM/yyyy"/>
</h:inputText>
<h:outputLabel value="Email: " />
<h:inputText value="#{contato.contato.email}" />
<h:outputLabel value="Endereco: " />
<h:inputText value="#{contato.contato.endereco}" />
<h:commandButton value="Cadastrar" actionListener="#{contato.salvarContato}" action="lista"/>
</h:panelGrid>
</h:form>
<h1>Ultimos Cadastrados</h1>
<h:dataTable value="#{contato.ultimosCadastados}"
var="item" rendered="#{not empty contato.ultimosCadastados}">
<h:column>
<f:facet name="header">
<h:outputLabel value="ID" />
</f:facet>
<h:outputText value="#{item.id}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Nome" />
</f:facet>
<h:outputText value="#{item.nome}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Email" />
</f:facet>
<h:outputText value="#{item.email}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Endereco" />
</f:facet>
<h:outputText value="#{item.endereco}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Data de Nascimento" />
</f:facet>
<h:outputText value="#{item.dataNascimento}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputLabel value="Opções" />
</f:facet>
<h:panelGroup>
<h:form>
<h:commandLink action="editar">
<h:graphicImage value="/img/icones/delete.png" width="15px" height="15px"/>
</h:commandLink>
<h:commandLink actionListener="#{contato.removerContato}">
<h:graphicImage value="/img/icones/update.png" width="15px" height="15px"/>
</h:commandLink>
</h:form>
</h:panelGroup>
</h:column>
</h:dataTable>
</ui:define>
</ui:composition>
[/code]
meu bean
[code]package br.com.ceuma.bean;
import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ActionEvent;
import br.com.ceuma.dao.DAO;
import br.com.ceuma.model.Contato;
import br.com.ceuma.dao.ContatoDAO;
public class ContatoBean {
private DAO<Contato> banco;
private Contato contato;
private List<Contato> ultimosCadastados;
public ContatoBean() {
DAO<Contato> dao = new ContatoDAO();
this.banco = dao;
this.contato = new Contato();
this.ultimosCadastados = new ArrayList<Contato>();
}
public Contato getContato() {
return contato;
}
public void setContato(Contato contato) {
this.contato = contato;
}
public List<Contato> getUltimosCadastados() {
return ultimosCadastados;
}
private void addToArrayCadastrados(Contato e){
this.ultimosCadastados.add(e);
}
private void removeToArrayCadastrados(Contato e){
this.ultimosCadastados.remove(e);
}
public void salvarContato(ActionEvent ev){
try {
this.banco.save(getContato());
this.banco.finalizar();
this.addToArrayCadastrados(getContato());
} catch (Exception e) {
this.banco.finalizar(e);
} finally {
this.banco = new ContatoDAO();
this.contato = new Contato();
}
}
public void removerContato(ActionEvent ev){
System.out.println(this.getContato().getNome());
try {
this.banco.remove(getContato());
this.banco.finalizar();
this.removeToArrayCadastrados(getContato());
} catch (Exception e) {
this.banco.finalizar(e);
} finally {
this.banco = new ContatoDAO();
this.contato = new Contato();
}
}
}
[/code]
minha classe contato
[code]package br.com.ceuma.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name=“tb_contato”)
public class Contato {
@Id @GeneratedValue
private Long id;
private String nome;
@Column(unique=true)
private String email;
private String endereco;
@Column(name="data_nascimento")
private Date dataNascimento;
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 getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public Date getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(Date dataNascimento) {
this.dataNascimento = dataNascimento;
}
}
[/code]
pessoal… a parte de persistencia esta OK… mas o metodo nem é chamado quando eu clico na imagem que chama o metodo =(