How bind primefaces datatable in managedbean? How put the data, and how put columns?
My bean class:
public class BeanTest implements Serializable{
private String name;
private String email;
private int age;
//getters and setters
}
My managed bean:
public class TestTable implements Serializable{
private DataTable tabela;
private List<BeanTest> lista;
@PostConstruct
public void init() {
int age= 18;
this.lista = new ArrayList<>();
this.lista.add(new BeanTest("name1", "email1", age));
this.lista.add(new BeanTest("name2", "email2", age++));
this.lista.add(new BeanTest("name3", "email3", age++));
this.tabela = new DataTable();
Column column1 = new Column();
column1.setHeaderText("Nome");
Column column2 = new Column();
column2.setHeaderText("Email");
Column column3 = new Column();
column3.setHeaderText("Idade");
this.getTabela().getChildren().add(column1);
this.getTabela().getChildren().add(column2);
this.getTabela().getChildren().add(column3);
this.getTabela().setValue(this.lista);
}
}
JSF page:
<p:dataTable id="datalist" binding="#{testeTabela.tabela}">
</p:dataTable>
This display the table with three columns (correct, number and headers) and three rows(correct numbers), but there's no data in my rows. Empty table only with borders cells.
What's happening? How could i bind columns and data?
binding
and tedious Java code ways until/unless absolutely necessary in some (very) special cases which in this case appears to be absolutely superfluous. Check out examples on the showcase. (Do not forget to click the respective links on that page). – Tiny