Today''s Page Hits: 383
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 =
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>