I'm trying to implement a table with lazy loading. I think I got all steps from demo page and documentation but I always get a "No records found" message. I think I've reduced code to minimun expression, at least there should be one record :
Tables page:
<h:form id="listaEmpresas">
<p:dataTable id="tablaEmpresas" value="#{empresasTableMB.lazyDataModel}" var="empresa">
<p:column>
<f:facet name="header">
<h:outputText value="#{msgs.empresa_tabla_nombre}"/>
</f:facet>
<h:outputText value="#{empresa.nombre} "/>
</p:column>
</p:dataTable>
</h:form>
LazyDataModel:
@Override
public List<Empresa> load(int first, int pageSize, String sortField, SortOrder so, Map<String, String> filters) {
List<Empresa> listaEmpresas = new ArrayList();
Empresa e = new Empresa();
e.setNombre("Company");
listaEmpresas.add(e);
this.setRowCount(1);
return listaEmpresas;
}
@Override
public void setRowIndex(int rowIndex) {
if (rowIndex == -1 || getPageSize() == 0) {
super.setRowIndex(-1);
}
else
super.setRowIndex(rowIndex % getPageSize());
}
I must override setRowIndex or I get an exception "java.lang.ArithmeticException: / by zero". I'm using primefaces-3.1-SNAPSHOT, jsf 2.0.3, and tomcat 6.0. Please help. What I´m missing?
Add lazy=true
in your dataTable.
After adding this datatable is able to call your load()
method.
you need to add field private int rowCount;
and then in your load(...)
method set value of number of record in your list to this field (rowCount
).
without this thing <p:dataTable ...>
will gain "No record found" and also if you don't specify rows ="10"
(for example) attribute it will not render rows!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With