Primefaces lazyLoading数据表中源的使用列表
我有一份数据非常丰富的清单。我想在Primeface数据表中显示具有延迟加载能力的数据。现在我在数据表中显示数据正常,但速度很慢。 如何使用惰性加载能力 XHTML文件:Primefaces lazyLoading数据表中源的使用列表,primefaces,datatable,Primefaces,Datatable,我有一份数据非常丰富的清单。我想在Primeface数据表中显示具有延迟加载能力的数据。现在我在数据表中显示数据正常,但速度很慢。 如何使用惰性加载能力 XHTML文件: <ui:composition template="template.xhtml"> <ui:define name="content"> <p:panel id="pnlLogInformationPage"> <h:form id="logInformati
<ui:composition template="template.xhtml">
<ui:define name="content">
<p:panel id="pnlLogInformationPage">
<h:form id="logInformation">
<div class="contentContainer-full-left">
<p:dataTable var="log" value="#{logInformationMB.logInformationList}" id="logTable"
width="100%" liveResize="true">
<p:column headerText="ID" sortBy="Id">
<h:outputText value="#{logInformation.Id}" />
</p:column>
<p:column headerText="Name" sortBy="Name">
<h:outputText value="#{logInformation.Name}" />
</p:column>
</p:dataTable>
</div>
</h:form>
</p:panel>
</ui:define>
ManageBean文件:
@ManagedBean(name = "logInformationMB")
@ViewScoped
public class LogManagedBean implements Serializable {
@PostConstruct
public void initComponents() {
loadLogInformation();
}
public List<LogInformationDTO> getLogInformationList() {
return logInformationList;
}
public void setLogInformationList(final List<LogInformationDTO> pLogInformationList) {
logInformationList = pLogInformationList;
}
public void loadLoagInformation(final ComponentSystemEvent event) {
setLogLInformationlist(getLogInformationList();
}
public void loadInformationProtokolle() {
loadInformationProtokolle(null);
}
public List<LogInformationDTO> getLogInformation() {
final List<LogInformationDTO> lcResult = new ArrayList<LogInformationDTO>();
....
return lcResult;
}
}
@ManagedBean(name=“logInformationMB”)
@视域
公共类LogManagedBean实现可序列化{
@施工后
公共组件(){
loadLogInformation();
}
公共列表GetLoginInformationList(){
返回登录信息列表;
}
public void setLogInformationList(最终列表pLogInformationList){
logInformationList=pLogInformationList;
}
公共无效loadLoagInformation(最终组件系统事件){
setLogLInformationlist(getLoginInformationList();
}
公共void loadInformationProtokolle(){
loadInformationProtokolle(空);
}
公共列表GetLoginInformation(){
最终列表lcResult=new ArrayList();
....
返回结果;
}
}
根据您的代码,您没有使用懒散加载。您只需要获取所有数据。
当您的数据太大时,速度会很慢
请参见下面我的步骤:
1-您需要创建扩展LazyDataModel类的新类,并创建一个可以逐页获取数据的服务,而不是使用#{logInformationMB.logInformationList}
public class LogInformationDataModel extends LazyDataModel<LogInformationDTO> {
private List<LogInformationDTO> logInformationList;
private LogInformationService logInformationService = new LogInformationService();
@Override
public List<LogInformationDTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
// TODO implement sort
setRowCount(logInformationService.count(filters));
logInformationList = logInformationService.list(first / pageSize, pageSize, sortField, sort, filters);
return logInformationList;
}
@Override
public LogInformationDTO getRowData(String rowKey) {
for(LogInformationDTO logInformation : logInformationList) {
if(logInformation.getId().equals(rowKey))
return logInformation;
}
return null;
}
@Override
public Object getRowKey(LogInformationDTO logInformation) {
return logInformation.getId();
}
}
3-将lazy属性(lazy=“true”)添加到p:dataTable并使用分页
<p:dataTable var="log" value="#{logInformationMB.dataModel}" var="logInformation" id="logTable"
width="100%"
lazy="true"
paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,50,100"
>
<p:column headerText="ID" sortBy="Id">
<h:outputText value="#{logInformation.Id}" />
</p:column>
<p:column headerText="Name" sortBy="Name">
<h:outputText value="#{logInformation.Name}" />
</p:column>
</p:dataTable>
我希望我的回答能解决你的问题
以下是您可以查看的链接:
首先查看PrimeFaces showcase和文档。然后搜索Google、Stackoverflow等,当您遇到实际的编码问题时,请问一个更具体的问题。这个问题太笼统了/broad/rtfm。。。
<p:dataTable var="log" value="#{logInformationMB.dataModel}" var="logInformation" id="logTable"
width="100%"
lazy="true"
paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,50,100"
>
<p:column headerText="ID" sortBy="Id">
<h:outputText value="#{logInformation.Id}" />
</p:column>
<p:column headerText="Name" sortBy="Name">
<h:outputText value="#{logInformation.Name}" />
</p:column>
</p:dataTable>