This is the second post in a series of ZK MVC
This post is continuation of previous post
ZK Documentation is here
http://books.zkoss.org/wiki/Small_Talks/2008/August/ZK_MVC_Made_Easy
Now we will use Genericcomposer class to reduce some code from my previous post
Here is my zul file
<?page title="Example7" contentType="text/html;charset=UTF-8"?>
<zk>
<label
value=" http://books.zkoss.org/wiki/Small_Talks/2008/August/ZK_MVC_Made_Easy.
org.zkoss.zk.ui.util.GenericComposer utility class"
style="font-size : 18px;font-family: verdana,arial,sans-serif;" />
<separator />
<window title="MVC Pattern using org.zkoss.zk.ui.util.GenericComposer utility class" border="normal" width="300px" apply="com.me.Example7">
<grid>
<columns>
<column label="" />
<column label="" />
</columns>
<rows>
<row>
First Name :
<textbox id="firstName" />
</row>
<row>
Last Name :
<textbox id="lastName" />
</row>
<row>
Address :
<textbox id="address" />
</row>
<row>
<button id="Clear" label="Clear" forward="onClick=onClear_btn"/>
</row>
</rows>
</grid>
</window>
</zk>
Here is my Composer
package com.me;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericComposer;
import org.zkoss.zul.Textbox;
@SuppressWarnings("rawtypes")
public class Example7 extends GenericComposer {
/**
*
*/
private static final long serialVersionUID = 1L;
private Textbox firstName;
private Textbox lastName;
private Textbox address;
public void doAfterCompose(Component comp) throws Exception {
/**
* Dont forget to call super doaftercomposer. By calling this, it will add the event listner for us
*/
super.doAfterCompose(comp);
// locate ZK components
firstName = (Textbox) comp.getFellow("firstName");
lastName = (Textbox) comp.getFellow("lastName");
address = (Textbox) comp.getFellow("address");
// all addEventListener and new EventListener() codes are removed
}
public void onClear_btn(Event event) {
firstName.setValue("");
lastName.setValue("");
address.setValue("");
}
}
Here is the demo with source code download.......
0 comments:
Post a Comment