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

 

zul页面:

 

 

  zul 页面:
<?xml version="1.0" encoding="utf-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="userWin"?>

<window id="userWin" width="100%" use="com.linktel.linkFax.web.zk.controller.UserController"
	xmlns:h="http://www.w3.org/1999/xhtml" xmlns:n="http://www.zkoss.org/2005/zk/native"
	xmlns="http://www.zkoss.org/2005/zul" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">

          <listbox id="userLbx" model="@{userWin.userList}" fixedLayout="true"   paginal="@{pagingUser}" selectedItem="@  
                     {userWin.user}">
                  <listhead sizable="true">
                    <listheader label="用户名"></listheader>
                    <listheader label="手机号"></listheader>
                    <listheader label="分机号"></listheader>
                    <listheader label="公司名称"></listheader>
                    <listheader label="部门名称"></listheader>
                    <listheader label="职位"></listheader>
                    <listheader label="传真"></listheader>
                     <listheader label="角色"></listheader>
                    <listheader label="启用状态"></listheader>
                    <listheader label="创建时间" ></listheader>
                   </listhead>
                   
                   <listitem self="@{each=user}" forEach="@{user.roles}">
                           <listcell label="@{user.username}"></listcell>
                           <listcell label="@{user.phone}"></listcell>
                           <listcell label="@{user.exten}"></listcell>
                           <listcell label="@{user.coname}"></listcell>
                           <listcell label="@{user.deptname}"></listcell>
                           <listcell label="@{user.position}"></listcell>
                           <listcell label="@{user.fax}"></listcell>
                           <listcell  label="@{each.name}"></listcell>
                           <listcell label="@{user.enabled}"></listcell>
                           <listcell label="@{user.createtime}"></listcell>
                   </listitem>
           </listbox>
				
           <paging id="pagingUser"  pageSize="2"></paging>
</window>
 

 

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

 

 

java  代码:
package com.linktel.linkFax.web.zk.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zkplus.databind.AnnotateDataBinder;
import org.zkoss.zkplus.spring.SpringUtil;

import org.zkoss.zul.Window;
import org.zkoss.zul.api.Listbox;
import org.zkoss.zul.api.Paging;
import org.zkoss.zul.event.PagingEvent;

import com.linktel.linkFax.dao.support.Page;
import com.linktel.linkFax.domain.Authority;
import com.linktel.linkFax.domain.Role;
import com.linktel.linkFax.domain.User;
import com.linktel.linkFax.service.UserService;


@SuppressWarnings("serial")
public class UserController extends Window implements AfterCompose{
     
       private User user = new User();
	protected AnnotateDataBinder binder;
	public List<User> userList;
	protected Listbox userLbx;

	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
        public  void setUserList(List<User> userList) {
		this.userList = userList;
	}

	@Override
	public void afterCompose() {
		Components.wireVariables(this, this);
		Components.addForwards(this, this);
		
		onGetUser();//页面初始化的时候条用此方法
	}

	public void onCreate() {
		binder = (AnnotateDataBinder) this.getVariable("binder", true);

	}

	public List<User> onGetUserList() {
		return userList;
	}

	public void onGetUser() {
  
	       final UserService service  = (UserService) SpringUtil.getBean("userService");
	      final Paging paging= (Paging) this.getFellow("pagingUser");//找到id命名为pagingUser的paging组件
	      int totalSize=service.countUser();  //查询出所有数据的记录数;
	      paging.setTotalSize(totalSize);   //设置paging组件的总记录数;
	      final int pageSize=paging.getPageSize();  //这个我不详细描述了自己想....
               /**
               *下面就是为paging组件添加事件监听器 "onPaging"事件
               *
               */
	      paging.addEventListener("onPaging", new EventListener() {
					public void onEvent(Event event) throws Exception {
						    PagingEvent pagingEvt=(PagingEvent) event;//转化成PaingEvent事件

						    Page<User> pu=new Page<User>();//这个是我自己写的工具类
 										   //其实就是将传入参数pageSize,pageNo的封装
									   	   
						    pu.setAutoCount(true);
						    pu.setPageNo( pagingEvt.getActivePage());
						    pu.setPageSize(pageSize);
						      Page<User>  pageUser=    service.pagedUser(pu,user);//后台biz层的数据访问
						      userList=  pageUser.getResult();//result返回一个集合对象全部数据
						       binder.loadComponent(userLbx);//这个不加阐述了
					}
				});
	         
	}

}

你可能感兴趣的:(spring,Web,UI,ext,zk)