ZK Paging组件实现动态分页,描述很通俗易懂

zul页面:

 

 

Xml代码   收藏代码
  1.   zul 页面:  
  2. <?xml version="1.0" encoding="utf-8"?>  
  3. <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="userWin"?>  
  4.   
  5. <window id="userWin" width="100%" use="com.linktel.linkFax.web.zk.controller.UserController"  
  6.     xmlns:h="http://www.w3.org/1999/xhtml" xmlns:n="http://www.zkoss.org/2005/zk/native"  
  7.     xmlns="http://www.zkoss.org/2005/zul" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  8.     xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">  
  9.   
  10.           <listbox id="userLbx" model="@{userWin.userList}" fixedLayout="true"   paginal="@{pagingUser}" selectedItem="@    
  11.                      {userWin.user}">  
  12.                   <listhead sizable="true">  
  13.                     <listheader label="用户名"></listheader>  
  14.                     <listheader label="手机号"></listheader>  
  15.                     <listheader label="分机号"></listheader>  
  16.                     <listheader label="公司名称"></listheader>  
  17.                     <listheader label="部门名称"></listheader>  
  18.                     <listheader label="职位"></listheader>  
  19.                     <listheader label="传真"></listheader>  
  20.                      <listheader label="角色"></listheader>  
  21.                     <listheader label="启用状态"></listheader>  
  22.                     <listheader label="创建时间" ></listheader>  
  23.                    </listhead>  
  24.                      
  25.                    <listitem self="@{each=user}" forEach="@{user.roles}">  
  26.                            <listcell label="@{user.username}"></listcell>  
  27.                            <listcell label="@{user.phone}"></listcell>  
  28.                            <listcell label="@{user.exten}"></listcell>  
  29.                            <listcell label="@{user.coname}"></listcell>  
  30.                            <listcell label="@{user.deptname}"></listcell>  
  31.                            <listcell label="@{user.position}"></listcell>  
  32.                            <listcell label="@{user.fax}"></listcell>  
  33.                            <listcell  label="@{each.name}"></listcell>  
  34.                            <listcell label="@{user.enabled}"></listcell>  
  35.                            <listcell label="@{user.createtime}"></listcell>  
  36.                    </listitem>  
  37.            </listbox>  
  38.                   
  39.            <paging id="pagingUser"  pageSize="2"></paging>  
  40. </window>  
 

 

Java 代码绑定paging动态分页绑定数据

 

 

Java代码   收藏代码
  1. java  代码:  
  2. package com.linktel.linkFax.web.zk.controller;  
  3.   
  4. import java.util.ArrayList;  
  5. import java.util.Date;  
  6. import java.util.List;  
  7.   
  8. import org.zkoss.zk.ui.Components;  
  9. import org.zkoss.zk.ui.event.Event;  
  10. import org.zkoss.zk.ui.event.EventListener;  
  11. import org.zkoss.zk.ui.ext.AfterCompose;  
  12. import org.zkoss.zkplus.databind.AnnotateDataBinder;  
  13. import org.zkoss.zkplus.spring.SpringUtil;  
  14.   
  15. import org.zkoss.zul.Window;  
  16. import org.zkoss.zul.api.Listbox;  
  17. import org.zkoss.zul.api.Paging;  
  18. import org.zkoss.zul.event.PagingEvent;  
  19.   
  20. import com.linktel.linkFax.dao.support.Page;  
  21. import com.linktel.linkFax.domain.Authority;  
  22. import com.linktel.linkFax.domain.Role;  
  23. import com.linktel.linkFax.domain.User;  
  24. import com.linktel.linkFax.service.UserService;  
  25.   
  26.   
  27. @SuppressWarnings("serial")  
  28. public class UserController extends Window implements AfterCompose{  
  29.        
  30.        private User user = new User();  
  31.     protected AnnotateDataBinder binder;  
  32.     public List<User> userList;  
  33.     protected Listbox userLbx;  
  34.   
  35.     public User getUser() {  
  36.         return user;  
  37.     }  
  38.     public void setUser(User user) {  
  39.         this.user = user;  
  40.     }  
  41.         public  void setUserList(List<User> userList) {  
  42.         this.userList = userList;  
  43.     }  
  44.   
  45.     @Override  
  46.     public void afterCompose() {  
  47.         Components.wireVariables(thisthis);  
  48.         Components.addForwards(thisthis);  
  49.           
  50.         onGetUser();//页面初始化的时候条用此方法  
  51.     }  
  52.   
  53.     public void onCreate() {  
  54.         binder = (AnnotateDataBinder) this.getVariable("binder"true);  
  55.   
  56.     }  
  57.   
  58.     public List<User> onGetUserList() {  
  59.         return userList;  
  60.     }  
  61.   
  62.     public void onGetUser() {  
  63.     
  64.            final UserService service  = (UserService) SpringUtil.getBean("userService");  
  65.           final Paging paging= (Paging) this.getFellow("pagingUser");//找到id命名为pagingUser的paging组件  
  66.           int totalSize=service.countUser();  //查询出所有数据的记录数;  
  67.           paging.setTotalSize(totalSize);   //设置paging组件的总记录数;  
  68.           final int pageSize=paging.getPageSize();  //这个我不详细描述了自己想....  
  69.                /** 
  70.                *下面就是为paging组件添加事件监听器 "onPaging"事件 
  71.                * 
  72.                */  
  73.           paging.addEventListener("onPaging"new EventListener() {  
  74.                     public void onEvent(Event event) throws Exception {  
  75.                             PagingEvent pagingEvt=(PagingEvent) event;//转化成PaingEvent事件  
  76.   
  77.                             Page<User> pu=new Page<User>();//这个是我自己写的工具类  
  78.                                            //其实就是将传入参数pageSize,pageNo的封装  
  79.                                              
  80.                             pu.setAutoCount(true);  
  81.                             pu.setPageNo( pagingEvt.getActivePage());  
  82.                             pu.setPageSize(pageSize);  
  83.                               Page<User>  pageUser=    service.pagedUser(pu,user);//后台biz层的数据访问  
  84.                               userList=  pageUser.getResult();//result返回一个集合对象全部数据  
  85.                                binder.loadComponent(userLbx);//这个不加阐述了  
  86.                     }  
  87.                 });  
  88.                
  89.     }  
  90.   


你可能感兴趣的:(java,user,zk,手机,each,encoding)