搭建简易ZK框架并实现简单交互

第一步:Eclipse下安装ZK插件环境,Help → Install New Software

                链接地址:http://studio.zkoss.org/resource/plugins/eclipse_4_2

搭建简易ZK框架并实现简单交互_第1张图片

第二步:创建Maven Web项目,项目大体结构如下:

                教程:如何创建MavenWeb项目?

                搭建简易ZK框架并实现简单交互_第2张图片

第三步:pom.xml 内容如下:


    4.0.0
    com.potix
    zkdemo-Load_On_Demand___Grid
    8.0
    war

    
        8.0.3.1-Eval
        2.1.1-Eval
        yyyy-MM-dd
    

    
        
            zk repository
            http://mavensync.zkoss.org/maven2
        
        
            ZK Evaluation
            http://mavensync.zkoss.org/eval
        
        
            com.asual.maven.public
            Asual Public Repository
            http://www.asual.com/maven/content/groups/public
        
    

    
        
            org.apache.velocity
            velocity
            1.6
        
              
        
            org.zkoss.zk
            zk
            ${zk.version}
        
        
            org.zkoss.zk
            zhtml
            ${zk.version}
        
        
            org.zkoss.zk
            zml
            ${zk.version}
        
        
            org.zkoss.zk
            zul
            ${zk.version}
        
        
            org.zkoss.common
            zcommon
            ${zk.version}
        
        
            org.zkoss.common
            zweb
            ${zk.version}
        
        
            org.zkoss.common
            zel
            ${zk.version}
        
        
            org.zkoss.zk
            zkbind
            ${zk.version}
        

        
        
            org.zkoss.zk
            zkmax
            ${zk.version}
        
        
            org.zkoss.zk
            zkplus
            ${zk.version}
        
        
            org.zkoss.zk
            zkex
            ${zk.version}
        

        
        
            org.zkoss.chart
            zkcharts
            ${zkcharts.version}
        

        
        
            org.zkoss.graphics
            graphics
            0.8.0
        
        
        
            org.zkoss.zk
            zuljsp
            2.0
        

        
        
            org.zkoss.addon
            flashchart
            1.0
        
        
            org.zkoss.zkforge
            gmapsz
            3.0.4
        
        
            org.zkoss.zkforge
            ckez
            4.4.6.3
        
        
            org.zkoss.calendar
            calendar
            2.1.5
        
        
            org.zkoss.pivot
            pivottable
            2.3.0-Eval
        

        
        
            org.zkoss.theme
            sapphire
            ${zk.version}
        
        
            org.zkoss.theme
            silvertail
            ${zk.version}
        

        
        
            javax.servlet
            servlet-api
            2.5
        

        
        
            commons-io
            commons-io
            1.3.1
        
        
            commons-logging
            commons-logging
            1.1.1
        
        
            commons-digester
            commons-digester
            2.0
        
        
            commons-collections
            commons-collections
            3.2.1
        

        
        
            log4j
            log4j
            1.2.16
        

        
            org.slf4j
            slf4j-simple
            1.6.4
        

        
            org.apache.geronimo.ext.tomcat
            juli
            7.0.23.1
            test
        

        
        
            rome
            rome
            1.0
        

        
        
            net.sf.jasperreports
            jasperreports
            4.0.1
        

        
        
            jfree
            jfreechart
            1.0.13
        
        
            jfree
            jcommon
            1.0.16
        


        
        
            org.apache.poi
            poi
            3.7
        

        
        
            com.jhlabs
            filters
            2.0.235
        

    
第四步:web.xml 内容如下:

 
	
        
	
		ZK listener for cleanup when a session is destroyed
		org.zkoss.zk.ui.http.HttpSessionListener
	
	
		ZK loader for evaluating ZUML pages
		zkLoader
		org.zkoss.zk.ui.http.DHtmlLayoutServlet
		
		
			update-uri
			/zkau
		
		1
	
	
		zkLoader
		*.zul
	
	
		zkLoader
		*.zhtml
	
	
		The asynchronous update engine for ZK
		auEngine
		org.zkoss.zk.au.http.DHtmlUpdateServlet
	
	
		auEngine
		/zkau/*
	

        
	
		gif
		image/gif
	
	
		html
		text/html
	
	
		htm
		text/html
	
	
		jad
		text/vnd.sun.j2me.app-descriptor
	
	
		jpeg
		image/jpeg
	
	
		jpg
		image/jpeg
	
	
		js
		application/x-javascript
	
	
		png
		image/png
	
	
		txt
		text/plain
	
	
		xml
		text/xml
	
	
		zhtml
		text/html
	
	
		zul
		text/html
	
	
		index.zul
		index.zhtml
		index.html
		index.htm
	
第五步:前台页面Index.zul页面内容如下:


第六步:后台Java控制器代码如下:

package com.test.winhye;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Textbox;

/**
 * Hello world!
 *
 */
public class IndexController extends SelectorComposer {

    private static final long serialVersionUID = 1L;
    @Wire
    private Datebox in;
    @Wire
    private Textbox mTime;

    @Listen("onClick = #getCurrentTime")
    public void getTime(){
        System.out.println("=="+in);
        Date dateTime = in.getValue();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        mTime.setValue(sdf.format(dateTime));
        System.out.println("获取时间:"+in.getValue());
    }

}

将项目部署到tomcat,运行效果如下:


搭建简易ZK框架并实现简单交互_第3张图片


你可能感兴趣的:(ZK开发)