a data table intera over a list.
The value of the data table has to be a return list in the query to the bank. and the var attribute is each object in this list and can thus access its properties.
Example:
Java
class CarrinhoCompraBean {
public List<Item> getItems {
List<Item> items = consultaBanco(idCarrinho);
return items;
}
public static class Item {
// ...
}
}
And in your template, Html
<h:dataTable id="table1" value="#{carrinhoCompraBean.items}" var="item" >
<h:column>
<f:facet name="header">
<h:outputText value="Item" />
</f:facet>
<h:outputText value="#{item.nome}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Preço" />
</f:facet>
<h:outputText value="#{item.preco}" />
</h:column>
</h:dataTable>
javadoc datatable
datatable primefaces
It is not easier to return the
ResultSet
to thedataTable
?– ptkato
No Patrick, the resultset is not a list and the objects it returns are not pojos. You don’t have getName example on the return of a resultset. times that transform resultset and objects.
– heat
If I’m not mistaken, the component
dataGrid
of Primefaces allows this association, withResultSet
.– ptkato