0
My Entity:
package Entidades;
public class Aluno {
private String nome;
private int idade;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
this.idade = idade;
}
}
DAO:
package DAO;
import Entidades.Aluno;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AlunoDAO {
private Connection con;
public AlunoDAO(){
try {
con = new Conexao().conectar();
} catch (ClassNotFoundException ex) {
Logger.getLogger(AlunoDAO.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List<Aluno> Listar(){
String sql = "SELECT * FROM aluno";
List<Aluno> alunos = new ArrayList<>();
try {
PreparedStatement stat = con.prepareStatement(sql);
ResultSet rs = stat.executeQuery();
alunos = listar_Aluno(rs);
stat.close();
} catch (SQLException ex) {
Logger.getLogger(AlunoDAO.class.getName()).log(Level.SEVERE, null, ex);
}
return alunos;
}
private List<Aluno> listar_Aluno(ResultSet result) throws SQLException{
List<Aluno> comp = new ArrayList<>();
while(result.next()){
Aluno c1 = new Aluno();
c1.setNome(result.getString("nome"));
c1.setIdade(result.getInt("idade"));
comp.add(c1);
}
return comp;
}
}
The Xhtml page:
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<p:toolbar>
<p:toolbarGroup>
<p:commandButton value="Buscar" action="#{alunoBean.listar}" update="@form"/>
</p:toolbarGroup>
</p:toolbar>
<p:dataTable var="Alu" value="#{alunoBean.alunos}" >
<p:column headerText="Nome">
<h:outputText value="#{Alu.nome}"/>
</p:column>
<p:column headerText="Idade">
<h:outputText value="#{Alu.idade}"/>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
When I run the page the table is not updated, someone knows how to solve?
Leandro, you have already debugged your code to know if the list is populated from the database query?
– StatelessDev
Put the manegedbean on.
– Adriano Gomes