如何动态更改p:datatable的延迟加载的setRowCount [英] How to change setRowCount of lazyloading of p:datatable dynamically

查看:101
本文介绍了如何动态更改p:datatable的延迟加载的setRowCount的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的情况是分页应该是动态的.这意味着它应该随着load方法的每次调用而改变.

I have a situation where the pagination should be dynamically. Meaning that it should change with each call of the load method.

我想动态设置setRowCount()方法并给出dataTable的分页

I want set the setRowCount() method dynamically and give the pagination for the dataTable

@Override
public List<ProjectMasterModel> load(int first,int pageSize,StringsortField, SortOrder sortOrder, Map<String, String> filters) {
    List<ProjectMasterModel> data=new ArrayList<ProjectMasterModel>();
    LazyDataModel<ProjectMasterModel> newdata = null;
    ProjectMilestoneDaoImpl milestoneDaoImpl=(ProjectMilestoneDaoImpl) ObjectFactory.getBean("projectMilestoneDao");
    SessionFactory sessionFactory=(SessionFactory) ObjectFactory.getBean("sessionFactory");
    sessionFactory.getCurrentSession().beginTransaction();

    try{
        data.addAll(milestoneDaoImpl.populateLazyRandomProjects(first,pageSize));
        setRowCount(milestoneDaoImpl.getRowCount_Of_ProjectList());

        // very important line to show the pagination

    }catch(Exception e){
        CmsLogger.errorLog(LazyProjectDataModel.class, e);
    }finally{   
        sessionFactory.getCurrentSession().close();
    }

    if(sortField != null)
       Collections.sort(data,new ProjectMasterModel());

    return data;
}

在这里,我使用查询来获取数据大小以设置行数. 在给定的情况下,它们的数量可能是添加到数据库中的记录的数量. 因此,分页应动态增加. 但是,如果我将setRowCount()方法更改为一个动态值,它并不能反映它会保留其首次设置的原始值.

Here I have used a query to fetch the data size to set the row count. In a given situation their may be number of records added to the Database. So The pagination should increment dynamically. But if I change the setRowCount() method to a dynamic value it doesn't reflect it keeps its original value which was set for the first time.

推荐答案

MyMB.java

List<NameClass> listResult = new LazyDataModel<NameClass>() {

  private static final long serialVersionUID = 1L;

  @Override
  public List<NameClass> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {

    List<NameClass> result = dao.findReg(....., pageSize, page);
    setRowCount(numberOfResult);
    return result;
  }
};

getListResult() {..}
setListResult(List<NameClass> l ) {...}

myPage.xhtml

<p:dataTable lazy="true" 
 value="#{myMB.listResult}" 
 var="model" 
 paginator="true"
 rows="#{myMB.pageSize}" 
 paginatorPosition="bottom" 
 paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >

这篇关于如何动态更改p:datatable的延迟加载的setRowCount的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆