English 中文(简体)
OP LazyDataModel in pdata: 表1
原标题:Implement LazyDataModel in p:dataTable

I m 试图用 la装执行一个表格。 我认为,我从白页和文件上走过所有步骤,但我总是收到“没有记录”的信息。 我认为,我把法典削减到小型表达中,至少应该有一记录:

表1

<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!

You need to implement LazyDataModel#getRowKey and LazyDataModel#getRowData as well.

赞同:

class Empresa {

    private long id;
    private String nombre;

    // getters and setters...

}

然后:

  • getRowKey returns the id for an Empresa object
  • getRowData gets an Empresa object by 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();
    }

}

https://code.google.com/p/primefaces/issues/detail?id=1544“rel=“nofollow noreferer”>。 并且显然,你可以通过明确打电话lazyDataModel.setPageSize();)。

There is a related post here:

Primefaces DataTable + JPA / Hibernate Pagination

您不称装载方法。 首先是在主面数据表申报之前使用装载方法。





相关问题
problem with primefaces library (jsf)

i am new to primeface. i have tried to test an example of primefaces about tag as in its documentation, this is my jsf page code: <%@ page language="java" import="java.util.*" pageEncoding="...

Loading a set of images with primefaces

I have the next code to load a set of images whose streams are in a datamodel called names. My problem is when I declare the var inside the p:datatable tag seems like has nothing. Any idea? thx! <...

Primefaces Tree set checkboxes

I have a JSF application using Primefaces. I use the multiselect tree component which includes a checkbox on each tree node. My problem is that I need to preselect the tree nodes with values coming ...

Primefaces p:fileupload component problem

I am using Primefaces 2.0.1 but the FileUpload component is not working properly. It uses JQuery uploadify behind the scenes. This is my web.xml <?xml version="1.0" encoding="UTF-8"?> <web-...