您可以使用LazyDataModel。在此示例中,我将使用NetBeans通过“从实体创建JSF
CRUD页面”创建的BackBean和JpaController(BackBean必须为@SessionScoped)
private LazyDataModel<Car> lazyModel;private int pageSize = 5;public void setPageSize(int pageSize) { this.pageSize = pageSize;}public int getPageSize() { return pageSize;public void LoadData() { lazyModel = new LazyDataModel<Car>() { @Override public List<Car> load(int first, int pageSize, String sortField, boolean sortOrder, Map<String, String> filters) { //Sorting and Filtering information are not used for demo purposes just random dummy data is returned List<Car> result = new ArrayList<Car>(); try { result = getJpaController().findCarEntities(pageSize, first); } catch (Exception ex) { JsfUtil.addErrorMessage(ex, search); } return result; } }; lazyModel.setRowCount(getJpaController().getCarCount()); lazyModel.setPageSize(pageSize);}public LazyDataModel<Car> getLazyModel() { return lazyModel;}我已经添加
lazyModel.setPageSize(pageSize);
因为除以0知道问题http://pre.google.com/p/primefaces/issues/detail?id=1544
<p:dataTable var="item" value="#{controller.lazyModel}"rows="#{controller.pageSize}" paginator="true"paginatorTemplate="{CurrentPageReport} {FirstPagelink} {PreviousPagelink} {Pagelinks} {NextPagelink} {LastPagelink} {RowsPerPageDropdown}" rowsPerPageTemplate="9,12,15"page=""lazy="true"dynamic="true"id="pnlResult">


