ZK Framework(二、快速入门)
官网例子:http://books.zkoss.org/wiki/ZK_Getting_Started/Learn_ZK_in_10_Minutes
官网没有给出例子的源码,这里我整理到我的工程FastUiDemo了
下载地址:http://www.cnblogs.com/jrsmith/admin/Files.aspx
(一)业务流程
1、提供一个新用户注册界面,
2、响应同意协议事件
2、响应提交事件。
(二)工程
工程结构:
Registarion.zul:
2.1 改变了window的apply值
2.2 改变了图标的路径和后缀名
1 <window border="normal" width="400px" style="padding-top:20px;padding-left:20px;" title="Welcome! New User" 2 apply="com.core.controller.RegistrationComposer"> 3 <grid hflex="1"> 4 <auxhead> 5 <auxheader colspan="2" label="Registration Form" style="font-size:16px" image="/images/picture.gif"/> 6 </auxhead> 7 <columns/> 8 <rows> 9 <row> 10 User Name <textbox id="nameBox" hflex="1" constraint="no empty"/> 11 </row> 12 <row> 13 Gender: 14 <radiogroup id="genderRadio"> 15 <radio label="Male" value="male" image="/images/male.gif" checked="true"/> 16 <radio label="Female" value="female" image="/images/female.gif"/> 17 </radiogroup> 18 </row> 19 <row > 20 Birthday <datebox id="birthdayBox" hflex="1" constraint="no empty"/> 21 </row> 22 <row spans="2" align="center" > 23 <hlayout> 24 <checkbox id="acceptTermBox"/> Accept Term of Use 25 </hlayout> 26 </row> 27 <row spans="2" align="right"> 28 <hlayout> 29 <button id="resetButton" label="Reset" /> 30 <button id="submitButton" label="Submit" disabled="true"/> 31 </hlayout> 32 </row> 33 </rows> 34 </grid> 35 </window>
RegistrationComposer.java:
2.3 在全局变量里将注册信息带进来
2.4 在submit()中处理注册信息(Radiogroup组件仍待处理)
1 package com.core.controller; 2 3 import java.text.SimpleDateFormat; 4 5 import org.zkoss.zk.ui.Component; 6 import org.zkoss.zk.ui.select.SelectorComposer; 7 import org.zkoss.zk.ui.select.annotation.Listen; 8 import org.zkoss.zk.ui.select.annotation.Wire; 9 import org.zkoss.zul.Button; 10 import org.zkoss.zul.Checkbox; 11 import org.zkoss.zul.Datebox; 12 import org.zkoss.zul.Radiogroup; 13 import org.zkoss.zul.Textbox; 14 15 public class RegistrationComposer extends SelectorComposer<Component> { 16 17 private static final long serialVersionUID = 1L; 18 @Wire 19 private Textbox nameBox; 20 @Wire 21 private Radiogroup genderRadio; 22 @Wire 23 private Datebox birthdayBox; 24 @Wire 25 private Button submitButton; 26 @Wire 27 private Checkbox acceptTermBox; 28 29 @Listen("onCheck = #acceptTermBox") 30 public void changeSubmitStatus(){ 31 if (acceptTermBox.isChecked()){ 32 submitButton.setDisabled(false); 33 submitButton.setImage("/images/submit.gif"); 34 }else{ 35 submitButton.setDisabled(true); 36 submitButton.setImage(""); 37 } 38 } 39 40 @Listen("onClick = #submitButton") 41 public void submit(){ 42 // omit irrelevant code for brevity 43 SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 44 String dateString = formatter.format(birthdayBox.getValue()); 45 System.err.println("Register new user:" + nameBox.getValue() + "," + dateString); 46 // registrationDao.add(newUser); 47 } 48 }
(三)运行结果: