Tuesday, 24 April 2012

ZK MVC Using .GenericComposer utility class

This is the second post in a series of ZK MVC

This post is continuation of previous post

ZK Documentation is here

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"?>
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">
<column label="" />
<column label="" />
First Name :
<textbox id="firstName" />
Last Name :
<textbox id="lastName" />
Address :
<textbox id="address" />
<button id="Clear" label="Clear" forward="onClick=onClear_btn"/>


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;

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
// 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) {

Here is the demo with source code download.......

No comments:

Post a Comment

Passing Parameter between two files using MVVM

This examples shows how to pass parameter between two zul screens. In this example, we are passing some parameters from the parent vm to...