Primefaces不懒加载工作的DataTable滚动直播(Primefaces datatabl

2019-10-19 12:44发布

参照在后给出的建议, 在这里我想实现延迟加载与现场滚动处理大型数据集,但现场的滚动不发生时两和数据表scrollRows属性used.If我删除然后属性没有记录将displayed.Here是我的代码片段,我tried.Can有人请帮助我,如果我做错了什么。

JSF代码段

<p:dataTable id="arcRecList" var="data"
        value="#{archivedRecordBean.archModel}" lazy="true"
        tableStyle="table-layout:auto; width:80%;" styleClass="datatable"
        scrollable="true" scrollWidth="84%" scrollHeight="81%"
        columnClasses="columnwidth" liveScroll="true" scrollRows="20"
        filteredValue="#{archivedRecordBean.filteredArchiveItems}"
        resizableColumns="true" rows="20">


        <p:column headerText="Insured" filterBy="#{data.insuredName}"
           sortBy="#{data.insuredName}" filterMatchMode="contains"
           style="width:15%;white-space:pre-line;" escape="false"
           filterStyle="width:80% !important; margin-top:25px;"
           sortFunction="#{archivedRecordBean.sortColumn}">
           <h:outputText value="#{data.insuredName}" />
           <!--   style="width:250px" -->
        </p:column>
                             .
                             .
                             .

     </p:dataTable>

托管bean

@ManagedBean
@ViewScoped

public class ArchivedRecordBean implements Serializable {

   private List<LPINFO> archiveItems=null;
   private List<LPINFO>filteredArchiveItems;
   private LPINFO objLPINFO=null;
   JdbcConnection jdbcConnection=null;
   Connection connection=null;
   Statement selectStmt=null;
   ResultSet rs=null;
   private transient LazyDataModel<LPINFO> archModel;
   public ArchivedRecordBean()

   {


      getArchiveFields();

   }
   @PostConstruct
   public void init()
   {


      archModel=new LazyArchiveDataModel(archiveItems);
   }
   public List<LPINFO> getArchiveItems() {
      System.out.println("inside getter");
      return archiveItems;
   }
   public void setArchiveItems(List<LPINFO> archiveItems) {
      this.archiveItems = archiveItems;
   }
   public LPINFO getObjLPINFO() {
      return objLPINFO;
   }
   public void setObjLPINFO(LPINFO objLPINFO) {
      this.objLPINFO = objLPINFO;
   }

   public List<LPINFO> getFilteredArchiveItems() {
      return filteredArchiveItems;
   }
   public void setFilteredArchiveItems(List<LPINFO> filteredArchiveItems) {
      this.filteredArchiveItems = filteredArchiveItems;
   }


   public LazyDataModel<LPINFO> getArchModel() {



      return archModel;
   }
   public void setArchModel(LazyDataModel<LPINFO> archModel) {
      this.archModel = archModel;
   }
   public void getArchiveFields()
   {
      System.out.println("inside getArchiveFields");
      ArchiveRecordsDao daoObject=new ArchiveRecordsDao();
      archiveItems=daoObject.getArchiveRecords();




   }



}

DAO类

    public class ArchiveRecordsDao {

    JdbcConnection con = null;
    Connection connection;
    Statement selectStmt;

   public ResultSet rs = null;

   private List<LPINFO> archiveItems = null;

   public LPINFO objWorkSpaceItem = null;

   public List<LPINFO> getArchiveRecords()
   {

      try
      {
         con=new JdbcConnection();
         connection=con.getJdbcConnection();
         selectStmt=connection.createStatement();
         String query="select * from LPINFO where LPINFO.ClearDate < (select TOP 1 Tbl_CurrentYear.CurrentYear from dbo.Tbl_CurrentYear)"
               +"AND (LPINFO.ClearDate is not null)";
         rs=selectStmt.executeQuery(query);
         archiveItems=new ArrayList<LPINFO>();

         while(rs.next())
         {

            objWorkSpaceItem=new LPINFO();
            objWorkSpaceItem.setInsuredName(rs.getString("InsuredName"));
                        .
                        .
                        .
            archiveItems.add(objWorkSpaceItem);


         }


      }
      catch(Exception e)
      {
         e.printStackTrace();
      }
      finally
      {
         try {

            connection.close();
         } catch (SQLException e) {

            e.printStackTrace();
         }

      }
      return archiveItems;

   }

}

LazyDataModel类

   public class LazyArchiveDataModel extends LazyDataModel<LPINFO> {

    private List<LPINFO> datasource;

    public LazyArchiveDataModel(List<LPINFO> datasource) {
        this.datasource = datasource;
    }

    @Override
    public void setRowIndex(int rowIndex) {
        /*
         * The following is in ancestor (LazyDataModel):
         * this.rowIndex = rowIndex == -1 ? rowIndex : (rowIndex % pageSize);
         */
        if (rowIndex == -1 || getPageSize() == 0) {
            super.setRowIndex(-1);
        }
        else
            super.setRowIndex(rowIndex % getPageSize());
    }

    @Override
    public LPINFO getRowData(String rowKey) {
        for(LPINFO lpinfo : datasource) {
            if(lpinfo.getLPID().equals(rowKey))
                return lpinfo;
        }

        return null;
    }

    @Override
    public Object getRowKey(LPINFO lpinfo) {
        return lpinfo.getLPID();
    }

    @Override
    public List<LPINFO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) {
        List<LPINFO> data = new ArrayList<LPINFO>();

        //filter
        for(LPINFO lpinfo : datasource) {
            boolean match = true;

            for(Iterator<String> it = filters.keySet().iterator(); it.hasNext();) {
                try {
                    String filterProperty = it.next();
                    String filterValue = filters.get(filterProperty);
                    String fieldValue = String.valueOf(lpinfo.getClass().getField(filterProperty).get(lpinfo));

                    if(filterValue == null || fieldValue.startsWith(filterValue)) {
                        match = true;
                    }
                    else {
                        match = false;
                        break;
                    }
                } catch(Exception e) {
                    match = false;
                }
            }

            if(match) {
                data.add(lpinfo);
            }
        }

        //sort
        /*if(sortField != null) {
            Collections.sort(data, new LazySorter(sortField, sortOrder));
        }*/

        //rowCount
        int dataSize = data.size();
        this.setRowCount(dataSize);

        //paginate
        if(dataSize > pageSize) {
            try {
                return data.subList(first, first + pageSize);
            }
            catch(IndexOutOfBoundsException e) {
                return data.subList(first, first + (dataSize % pageSize));
            }
        }
        else {
            return data;
        }
    }
}

Answer 1:

因为我用的行会与scrollRows冲突理解的文档。

下面是关于这两个属性的PrimeFaces文档:

:(整数)的行数,以每页显示。 (分页)

scrollRows:(整数)的行数上加载实时滚动 (滚动)

现在,这里的问题不仅是行,我认为这是scrollWidth="84%" scrollHeight="81%"

如文档,这两个属性是整数(S),所以你不会看到,因为scrollHeight属性定义错误的任何记录逸岸。

scrollHeight属性 :(整数)滚动视口的高度。

scrollWidth(整数)滚动视口宽度。

尽量将它们设置成固定整数像素,像500。

希望这可以帮助。



文章来源: Primefaces datatable live scrolling not working with lazy loading