ZK提供两种分页方式,一种是自带的“mold="paging"”的形式;另一种是采用“<paging>”组件添加分页功能。具体实现如下:
第一种:采用自带的“mold="paging"”:
infoList.zul:
<zk>
<window id="mainwin" border="normal" width="600px"
apply="${myComposer}">
<listbox id="li" mold="paging" pageSize="5">
<listhead>
<listheader label="Id" sort="auto(Id)"/>
<listheader label="Name" sort="auto(Name)"/>
<listheader label="Address" sort="auto(Address)"/>
<listheader />
</listhead>
<listitem self="@{each=in }">
<listcell id="colId" label="@{in.id }"></listcell>
<listcell id="colName" label="@{in.name }"></listcell>
<listcell id="colAddr" label="@{in.address }"></listcell>
<listcell></listcell>
</listitem>
</listbox>
</window>
</zk>
后台控制类 MyComposer.java:
public class MyComposer extends GenericForwardComposer {
protected Textbox name;
protected Textbox address;
private Listbox li;
private Window mainwin;
private AnnotateDataBinder binder;
private Service service;
private List<Info> infoList;
private int totalsize;
public void setInfoList(List<Info> infoList) {
this.infoList = infoList;
}
public void setService(Service service) {
this.service = service;
}
public void onCreate$mainwin(Event event) throws Exception {
binder = new AnnotateDataBinder(mainwin);
binder.loadAll();
}
public void doAfterCompose(Component component) throws Exception {
super.doAfterCompose(component);
infoList = service.findAllInfos();
totalsize = infoList.size();
li.setModel(new ListModelList(infoList));
li.setItemRenderer(new ListitemRenderer() {
@Override
public void render(Listitem item, Object data) throws Exception {
// TODO Auto-generated method stub
Info itinfo = (Info) data;
Listcell colId = new Listcell();
Listcell colName = new Listcell();
Listcell colAddr = new Listcell();
colId.setLabel(itinfo.getId().toString());
colId.setParent(item);
colName.setLabel(itinfo.getName());
colName.setParent(item);
colAddr.setLabel(itinfo.getAddress());
colAddr.setParent(item);
}
});
}
}
第二种:采用“<paging>”组件进行分页:
paging.zul:
<zk>
<window id="pagingWin" title="paging" border="normal"
apply="${paging_ctrl}">
<grid>
<rows>
<row>人员列表:</row>
<row>
<listbox id="li" width="100%">
<listhead>
<listheader label="ID" sort="auto(Id)" />
<listheader label="姓名" />
<listheader label="地址" />
</listhead>
</listbox>
<separator />
</row>
</rows>
</grid>
<paging id="pge" pageSize="10"></paging>
</window>
</zk>
后台控制类Paging_ctrl.java:
public class Paging_ctrl extends GenericForwardComposer {
private AnnotateDataBinder binder;
private Window pagingWin;
private Listbox li;
private Paging pge;
private List<Info> infoList;
int maxCount = 0;
private Service service;
public void onCreate$pagingWin(Event event) throws Exception {
binder = new AnnotateDataBinder(pagingWin);
binder.loadAll();
}
public void doAfterCompose(Component component) throws Exception {
super.doAfterCompose(component);
maxCount = service.findAllInfos().size();
pge.setTotalSize(maxCount);
final int PAGE_SIZE = pge.getPageSize();
redraw(0, PAGE_SIZE);
pge.addEventListener("onPaging", new EventListener() {
public void onEvent(Event event) {
PagingEvent pe = (PagingEvent) event;
int pgno = pe.getActivePage();// 页数(从零计算)
int start = pgno * PAGE_SIZE;
redraw(start, PAGE_SIZE);
}
});
}
@SuppressWarnings("unchecked")
private void redraw(int offSet, int pageSize) {
li.getItems().clear();
List<Info> list = service.findInfoByPage(offSet, pageSize);
for (Info info : list) {
Listitem item = new Listitem();
item.setValue(info);
item.appendChild(new Listcell("" + info.getId()));
item.appendChild(new Listcell(info.getName()));
item.appendChild(new Listcell(info.getAddress()));
li.appendChild(item);
}
}
public void setService(Service service) {
this.service = service;
}
}
分析:
第一种方式是把数据全部加载到内存再进行分页,达到几十W跳数据后将降低性能;
而第二种方式则采用hibernate的分页查询方式,性能将大大加强。因此推荐第二种方式。
分享到:
相关推荐
ZK中利用paging组件, 结合MVC与MVVM两种模式,实现大量数据的动态分页。
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
GWT Advanced Table 是一个基于 GWT 框架的网页表格组件,可实现分页数据显示、数据排序和过滤等功能! Google Tag Library 该标记库和 Google 有关。使用该标记库,利用 Google 为你的网站提供网站查询,并且可以...
通过网络或磁盘等方式,把公钥编码传送给李四,李四接收到张三编码后的公钥,将其解码,李四用张三的公钥加密信息,并发送给李四,张三用自己的私钥解密从李四处收到的信息…… Java利用DES私钥对称加密代码实例 ...
X Window是一种协议。 unix图形环境是CDE:common desktop environment通用桌面环境。 linux系统结构:硬件、内核层、shell层、应用层、用户。 在安装linux的时候,会弹出 CD Found To begin testing the CD ...
设定字符串为“张三,你好,我是李四” 产生张三的密钥对(keyPairZhang) 张三生成公钥(publicKeyZhang)并发送给李四,这里发送的是公钥的数组字节 通过网络或磁盘等方式,把公钥编码传送给李四,李四接收到张三编码后...