primefaces - 多次调用 LazyDataModel 初始加载
问题描述
我有这个用 Primefaces 的 LazyDataModel 实现的数据表。一切正常,除了我第一次打开页面或刷新时的初始加载。load 方法被调用了 6-7 次。
当我更改页面、过滤或排序时,它正常工作,加载只调用一次。
由于我执行对数据库的调用,因此我想防止它在需要时被调用。
我有以下内容:
XHTML:
<p:outputPanel id="documentsPanel">
<h:form id="documentsForm">
<p:dataTable id="documentsTable"
widgetVar="documentsTable"
var="doc"
value="#{MyManagedBean.model}"
paginator="true" rows="20"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}"
currentPageReportTemplate="{totalRecords} #{c.NumberOfRequestFound}"
lazy="true">
...
</p:dataTable>
</h:form>
</p:outputPanel>
爪哇:
public class DocumentEncodingDataModel extends LazyDataModel<SelectableDocumentToBeEncodedDTO> {
@Override
public List<SelectableDocumentToBeEncodedDTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
....
}
@Override
public int getRowCount() {
return super.getRowCount();
}
@Override
public SelectableDocumentToBeEncodedDTO getRowData(String rowKey) {
log.debug("getRowData");
if (!StringUtils.isBlank(rowKey)) {
for (SelectableDocumentToBeEncodedDTO doc : currentDocumentsToBeEncoded) {
if (doc.getDocumentToBeEncoded().getId().toString().equals(rowKey)) {
return doc;
}
}
}
return null;
}
@Override
public Object getRowKey(SelectableDocumentToBeEncodedDTO doc) {
return doc.getDocumentToBeEncoded().getId();
}
}
Primefaces 版本:6.2 JSF 版本:2.1
解决方案
推荐阅读
- html - 通过 Xpath 移动光标
- javascript - 如何在 javascript 代码中更改 django 模板变量值?
- javascript - 如何在ajax请求期间禁用按钮
- php - AJAX 共享 JS 和 PHP 处理文件
- python - 如何在 matplotlib 的完全自定义位置放置次要刻度?
- java - Android xml 文件突然显示 java 代码。
- reactjs - 从状态副本中删除数据后反应 setState 不起作用
- node.js - 返回 axios 数据未定义
- c# - 为什么这种插入排序会返回索引超出范围异常?
- angular - Angular 6 ngClass 没有打开布尔值