Basic: LazyDataModel implementation

I am trying to implement a table with lazy loading. I think I have all the steps from the demo page and the documentation, but I always get the message “No entries”. I think I reduced the code to a minimun expression, at least there should be one entry:

Table:

<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 have to override setRowIndex or get the exception "java.lang.ArithmeticException: / by zero". I am using primefaces-3.1-SNAPSHOT, jsf 2.0.3 and tomcat 6.0. Please help. What am I missing?

+5
source share
5 answers

Add lazy=trueto your data table. After adding this, a datatable can call your method load().

+2
source

LazyDataModel#getRowKey LazyDataModel#getRowData.

, - :

class Empresa {

    private long id;
    private String nombre;

    // getters and setters...

}

:

  • getRowKey id Empresa
  • getRowData Empresa id
class MyLazyDataModel {

    // stuff you already have comes here...

    public Empresa getRowData(String rowKey) {
        return empresaRepository.getEmpresaById(Long.valueOf(rowKey));
    }

    public Object getRowKey(Empresa empresa) {
        return empresa.getId();
    }

}
0

load. .

0

private int rowCount; load(...) (rowCount). <p:dataTable ...> " ", rows ="10" (), !

0

All Articles