Boa noite à todos !
Não estou conseguindo imprimir uma lista de clientes em uma tela usando o JSF. Ao clicar no botão deveria apresentar uma lista de nomes em um dataTable, mas
isso não está acontecendo, alguém pode me ajudar?, lembrando que não apresenta nenhum erro, somente não apresenta a lista na tela.
Classe Cliente
public class Cliente {
private Integer codigo;
private String nome;
private String cidade;
public Cliente(Integer codigo, String nome, String cidade){
super();
this.codigo = codigo;
this.nome = nome;
this.cidade = cidade;
}
/**
* @return the codigo
*/
public Integer getCodigo() {
return codigo;
}
/**
* @param codigo the codigo to set
*/
public void setCodigo(Integer codigo) {
this.codigo = codigo;
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @return the cidade
*/
public String getCidade() {
return cidade;
}
/**
* @param cidade the cidade to set
*/
public void setCidade(String cidade) {
this.cidade = cidade;
}
}
Meu Manager Bean
@ManagedBean
@SessionScoped
public class ConsultaClienteBean {
private List<Cliente> clientes = new ArrayList<Cliente> ();
/** Creates a new instance of ConsultaClienteBean */
public ConsultaClienteBean() {
}
/**
* @return the clientes
*/
public List<Cliente> getClientes() {
return clientes;
}
public void consultar(ActionEvent event){
this.getClientes().clear();
this.getClientes().add(new Cliente(1,"João da Silva","Uberlândia"));
this.getClientes().add(new Cliente(2,"Manoel Souza","Uberaba"));
this.getClientes().add(new Cliente(4,"Cristina Melo","São Paulo"));
this.getClientes().add(new Cliente(5,"Sebastião Cardoso","São Paulo"));
this.getClientes().add(new Cliente(6,"Fransciso Borges","Uberaba"));
this.getClientes().add(new Cliente(7,"Juliano Messias","Rio de Janeiro"));
this.getClientes().add(new Cliente(8,"Maria Helena","Uberlandia"));
}
}
JSP
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<f:view>
<h:form id="frm">
<h:commandButton value="Consultar" actionListener="#{consultaClienteBean.consultar}"/>
<h:dataTable value="#{consultaClienteBean.clientes}" var="item" border="1" rendered="#{not empty consultaClienteBean.clientes}">
<h:column>
<h:outputText value="#{item.codigo}"/>
</h:column>
<h:column>
<h:outputText value="#{item.nome}"/>
</h:column>
<h:column>
<h:outputText value="#{item.cidade}"/>
</h:column>
</h:dataTable>
</h:form>
</f:view>
</body>
</html>