//前台页面的zul文件
=========================================================================================
userxml <?xml version="1.0" encoding="utf-8"?> <?page id="userPage"?> <?xel-method prefix="c" name="hasPermission" class="com.linktel.linkFax.web.zk.util.AuthorityTools" signature="com.linktel.linkFax.web.zk.util.AuthorityTools hasPermission(java.lang.String)"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./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}" onSelect="showUserEdit();"> <listhead> <listheader label="用户名" align="center"></listheader> <listheader label="手机号" align="center"></listheader> <listheader label="分机号" align="center"></listheader> <listheader label="职位" align="center"></listheader> <listheader label="传真" align="center"></listheader> <listheader label="启用状态" align="center"></listheader> </listhead> <listitem self="@{each=user}"> <listcell label="@{user.username}"></listcell> <listcell label="@{user.phone}"></listcell> <listcell label="@{user.exten}"></listcell> <listcell label="@{user.position}"></listcell> <listcell label="@{user.fax}"></listcell> <listcell label="@{user.enabled,converter='com.linktel.linkFax.web.zk.converter.DataConverter'}"></listcell> </listitem> </listbox> <paging id="pagingUser" pageSize="3"></paging> <label value="公司名称:"></label> <combobox id="cbxCom" model="@{userWin.companyList}"> <comboitem self="@{each=companyEdit}" label="@{companyEdit.name}" value="@{companyEdit.id}"></comboitem> </combobox> <label value="部门名称:"></label> <combobox id="cbxDep" model="@{userWin.deptList}" selectedItem="@{userWin.deptEdit}"> <comboitem self="@{each=deptEdit}" label="@{deptEdit.name}" value="@{deptEdit.id}"></comboitem> </combobox> </window>
=======================================================================
//后台绑定Controller类 下面有详细的注释 public class UserController extends Window implements AfterCompose { protected AnnotateDataBinder binder; private User user = new User(); private User u = new User(); private Chinaregion province = new Chinaregion(); private Chinaregion city = new Chinaregion(); private Chinaregion district = new Chinaregion(); private Role role = new Role(); private Company company = new Company(); protected Dept dept = new Dept(); private Company companyEdit = new Company(); private Dept deptEdit = new Dept(); private Combobox cbxCompany; protected Listbox userLbx; protected Paging pagingUser; protected Combobox cbxProvince; protected Combobox cbxCity; protected Combobox cbxDistrict; private Combobox cbxDept; private Combobox cbxCom; private Combobox cbxDep; private List<Company> companyList; private List<User> userList; private List<Dept> deptList; private List<Role> roleList; private List<Chinaregion> provinceList; private List<Chinaregion> cityList; private List<Chinaregion> districtList; public Dept getDeptEdit() { return deptEdit; } public void setDeptEdit(Dept deptEdit) { this.deptEdit = deptEdit; } public Dept getDept() { return dept; } public Chinaregion getDistrict() { return district; } public void setDistrict(Chinaregion district) { this.district = district; } public Chinaregion getProvince() { return province; } public Chinaregion getCity() { return city; } public void setCity(Chinaregion city) { this.city = city; } public void setProvince(Chinaregion province) { this.province = province; } public Role getRole() { return role; } public void setRole(Role role) { this.role = role; } public void setDept(Dept dept) { this.dept = dept; } public List<Chinaregion> getProvinceList() { return provinceList; } public void setProvinceList(List<Chinaregion> provinceList) { this.provinceList = provinceList; } public List<Chinaregion> getCityList() { return cityList; } public void setCityList(List<Chinaregion> cityList) { this.cityList = cityList; } public List<Chinaregion> getDistrictList() { return districtList; } public void setDistrictList(List<Chinaregion> districtList) { this.districtList = districtList; } public List<Role> getRoleList() { return roleList; } public void setRoleList(List<Role> roleList) { this.roleList = roleList; } public Company getCompany() { return company; } public void setCompany(Company company) { this.company = company; } public User getU() { return u; } public void setU(User u) { this.u = u; } public List<Dept> getDeptList() { return deptList; } public void setDeptList(List<Dept> deptList) { } public List<Company> getCompanyList() { return companyList; } public void setCompanyList(List<Company> companyList) { this.companyList = companyList; } public User getUser() { return user; } public List<User> getUserList() { return userList; } public void setUserList(List<User> userList) { this.userList = userList; } public void setUser(User user) { this.user = user; } public Company getCompanyEdit() { return companyEdit; } public void setCompanyEdit(Company companyEdit) { this.companyEdit = companyEdit; } /** * 组件创建时初始化的事件监听器 */ public void init() { // UserService service= (UserService) SpringUtil.getBean("userService"); // int count =service.countUser(); // pagingUser.setTotalSize(count); pagingUser.addEventListener(ZulEvents.ON_PAGING, new UserPagingEventListener()); userLbx.addEventListener(Events.ON_SELECT, new UserSelectedEventListener()); cbxProvince.addEventListener(Events.ON_SELECT, new ProvinceSelectedEventListener()); cbxCity.addEventListener(Events.ON_SELECT, new CitySelectedEventListener()); cbxCom.addEventListener(Events.ON_SELECT, new EditCompanySelectedEventListener()); if (judgeCompontent(cbxCompany)) { cbxCompany.addEventListener(Events.ON_SELECT, new CompanySelectedEventListener()); } } /** * 初始化所属公司下的部门列表 * * @param company */ public void initDept(Company company) { DeptService service = (DeptService) SpringUtil.getBean("deptService"); deptList = service.getDeptsByCoId(company); binder.loadComponent(cbxDep); } /** * 初始化公司列表 */ public void initCompany() { CompanyService service = (CompanyService) SpringUtil .getBean("companyService"); companyList = service.getCompanyAll(); } /** * 动态绑定变量值 */ @Override public void afterCompose() { Components.wireVariables(this, this); Components.addForwards(this, this); initiaData(); } class UserSelectedEventListener implements EventListener { @SuppressWarnings("unchecked") public void onEvent(Event event) throws Exception { String cId = user.getCoid(); // 获取Combobox组件中的Comboitem所有的子项集合 List<Comboitem> comsItems = cbxCom.getChildren(); // 使用List接口的迭代器,迭代每个Comboitem对象 Iterator<Comboitem> comsIt = comsItems.iterator(); // 是否有下个对象 while (comsIt.hasNext()) { // 迭代对象转换成Comboitem对象 Comboitem item = comsIt.next(); // 判断item中的值是否相等,如果相等 if (StringUtils.equals((String) item.getValue(), cId)) { // 如果相等 绑定并且选中该对象 cbxCom.setSelectedItemApi(item); // 把该事件放入时间列队的末尾,在所有事件都处理完 之后,将会立即处理该事件 Events.postEvent(Events.ON_SELECT, cbxCom, null); // 初始化部门对象 Company c = new Company(); c.setId(cId); initDept(c); break; } } } } class EditCompanySelectedEventListener implements EventListener { public void onEvent(Event event) throws Exception { if (deptList == null || deptList.isEmpty()) return; // 循环迭代Dept集合对象 for (Iterator<Dept> it = deptList.iterator(); it.hasNext();) { Dept each = it.next(); if (StringUtils.equals(user.getDeptid(), each.getId())) { deptEdit = each;// 赋值给cbxDep绑定的对象; // 重新绑定对象 binder.loadComponent(cbxDep); return; } } } }
==========================================================================================