JSF Datatable 大数据集分页
2008-07-30 05:00
302 查看
译文[未完成]:
使用datatable时,通常的做法是取出所有的数据,把数据绑定到datatable,然后让组件来完成分页动作,一般来说,当数据集较小时这样可以,但是,如果数据集有数百行,数千行,甚至更大量的的数据行会如何呢,这样很有可能引起内存问题,所以不是一个好的实现.之前在我们的项目中发生过这种最糟糕的事情.好消息是经过努力.在javax.faces.DataModel 上找到了解决方案.
实际上,扩展自uidata的组件 ,例如 DataTable,通过一个适配类和它的数据交互.DataModel. This class wraps the actual collection for example, if a list is bound to a datatable then a ListDataModel is created and the component use this ListDataModel to access it’s data. DataModel provides methods like getWrappedData, isRowAvailable, getRowData, getRowCount letting the component access the wrapped data the way datamodel determines. To give an example, In case the wrapped data is a list, getRowCount returns list.size().
The solution to the large data problem is to use a custom data model and show only the data page allowed by the page size of the datatable. Whenever a paging occurs, the data of the next page is fetched and displayed, by this way the whole data is never read, the idea is to load only the page size of data when needed. There are two key attributes of a datatable, “first” and “rows”, first refers to the starting element and rows refers to the page size to be displayed. So when the first is 10 and rows is 5, then data between 10 and 15 is displayed. A pager simply sets the first attribute and the rows elements of the datatable, and then datatable displays it’s data considering these attributes. Also when the pages defines the number of pages, it looks at the datatable’s getRowCount method. Following is the PagedDataModel class providing the solution based on these informations.
|
In order to the custom paging at the view layer, we need features to do the same thing at business layer. I’m going to present a way with Hibernate Criteria API, also Query API should do the job. If you are not using spring and hibernate there are other options to fetch paged data like oracle’s rownum. Anyway the method below is located at an Hibernate DAO class and accessed via Spring beans. Also there is another one to return only the size of the actual data.
|
<h:datatable id=”table1″ value=”#{didYouSeeZidanesHeaderToMaterazzi.myPagedDataModel}“>
…
…
…
</h:datatable>
Finally the last job is to create a PagedDataModel and return it in the getter as;
|
相关文章推荐
- JSF中使用dataScroller和dataTable实现分页及其相关问题
- JSF primefaces dataTable paginator 表格分页 问题
- 分页 jsf组件dataTable
- 续分页 jsf组件dataTable
- C#-DataTable分页代码
- DataTable中数据记录的排序、检索、合并、分页、统计
- DataTable 分页
- jquery-datatable实现表格加载,分页和删除功能
- [转]asp.net中对DataTable数据进行排序、检索、合并、分页、统计
- 保存JSF分页的状态
- 在JSF中实现分页(二)
- 基于myFaces的JSF技术使用中的一些经验(二)[godroad原创]--dataTable的使用
- JSF Datatable 大数据集分页(简单,已在项目中使用)
- WCF分布式开发步步为赢(8):使用数据集(DataSet)、数据表(DataTable)、集合(Collection)传递数据
- spring boot 下 dataTable|pagehelper 组合进行分页 筛选 排序
- DataTable已属于另一个数据集
- 转:"DataTable已属于另一个数据集"[
- JSF2.xdatatable分页控件与左侧菜单最简单应用
- 11-28 自己写一个数据集DataSet---ds,向其中添加一个数据表DataTable ---dt,并创建该表的列和行。然后将本本表作为数据源绑定到GradView中。
- DataTable 服务端模式 进行分页 排序搜索