Status

Blog::Calendar

« September 2010
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  
       
Today
XML

Blog::Navigation

Blog::Editing

Bookmarks::Blogroll

Blog::Referers

Today''s Page Hits: 383

Other sites

Google Analytics

Powered by Roller Weblogger.
All | JBoss&Seam | JSF | ZK | Music | General | Java
« How to write ZK... | Main | How to write ZK... »
20070426 Thursday April 26, 2007
How to write ZK Forge Component Part 2

My Button Forge Component

MyButton.java : Just one attribute – label

package atticcomp;

import org.zkoss.lang.Objects;

import org.zkoss.zk.ui.HtmlBasedComponent;

public class MyButton extends HtmlBasedComponent {

    private static final long serialVersionUID = 1L;

    String label;

    public String getLabel() {

        return label;

    }

    public void setLabel(String label) {

        if (label == null)

            label = "";

        if (!Objects.equals(this.label, label)) {

            this.label = label;

//note1

            invalidate();

        }

    }

    

    //Beacuse onClick is generic Event, So we don't need to register Event here.

    //static {

    //    new GenericCommand("onClick", Command.IGNORE_OLD_EQUIV);

    //};

}

 

l           Note1:Call invalidate, when new label is assigned.

 

mybutton.dsp : simple output yourName

 

<%@ taglib uri="/WEB-INF/tld/web/core.dsp.tld" prefix="c" %>

<c:set var="self" value="${requestScope.arg.self}"/>

<div id="${self.uuid}"${self.outerAttrs} z.type="atticz.attic.MyButton" onclick="if(zkau) zkau.onclick('${self.uuid}')">

    <span style="border:1px solid;cursor:pointer">${self.label}</span>

</div>

 

l           atticz.attic.MyButton in z.type means bind this component by script in atticz.attic module's zhMyButton object.

l           onclick of span will invoke zkau.onclick and pass uuid of this component as parameter. ZK client engine will send a ASAP event to server, and all listener which listen to 「onClick」 event of this component will be notified.

 

attic.js / MyButton  : Do not thing in this component. I don't know much detail about this, HaHa~.

 

zkMyButton = {};

zkMyButton.init = function (cmp) {

};

zkMyButton.cleanup = function (cmp) {

};

zkMyButton.setAttr = function (elm, name, value) {

    return false;

};

 

Sample file :

 

<?xml version="1.0" encoding="utf-8"?>

<window id="w" style="width:800px">

    <zscript>

            int count;

    </zscript>

    <MyButton label="Click Me" id="mybtn">

            <attribute name="onClick">

                    count++;

                    mybtn.setLabel("You Click "+count+" times");

            </attribute>

    </MyButton>

</window>

Runtime result :


Trackback URL: http://www.javaworld.com.tw/roller/atticcat/entry/2007_4_26_How_to_write_ZK_Forge_Component_Part_2
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed
Copyright (C) 2003, 閣樓貓的五四三 (About Cat)