Tuesday, 24 April 2012

ZK MVC Using GenericForwardComposer utility class

Welcome back

This is the 4th post in a series of ZK MVC

Here is the zk documentation and we are following that
and creating new example


Here is the Summary

Method 1 : Implements Composer
We implement Composer interface. Here we used getfellow method to hold the
reference for the UI Components and also we added listener to handle

Here is the Link for the first post

Method 2 : extends GenericComposer
Here, we removed all the event lisener by extending the GenericComposer
But remember, we need to call super doaftercompose.

Here is the link for the second post

Method 3: extends GenericAutowireComposer
Here, we removed all the getfellow methods and let them auto wired
Here we dont need override doaftercompose


Until now, the previous example codes always use the forward attribute in zul file to forward
event of the button click. Can we remove such forward attributes?"

The org.zkoss.zk.ui.util.GenericForwardComposer utility class is designed to fulfill this requirement. Note that GenericForwardComposer extends the GenericAutowireComposer class, so it has all features of its parent class(GenericAutowireComposer) and grandparent class(GenericComposer).

Here is my zul code

<?page title="Example7" contentType="text/html;charset=UTF-8"?>
value=" http://books.zkoss.org/wiki/Small_Talks/2008/August/ZK_MVC_Made_Easy.
Using org.zkoss.zk.ui.util.GenericForwardComposer utility class"
style="font-size : 18px;font-family: verdana,arial,sans-serif;" />
<separator />
title="MVC Pattern Using org.zkoss.zk.ui.util.GenericForwardComposer utility class"
border="normal" width="700px" apply="com.me.Example9">
<column label="" />
<column label="" />
First Name :
<textbox id="firstName" />
Last Name :
<textbox id="lastName" />
Address :
<textbox id="address" />
<button id="Clear" label="Clear" />


In the above code, we have used apply attribute of the XML. By this, we are associating
with a component, such that the composer can control the UI rooted the given component.

Here is composer(java file)

package com.me;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Textbox;

public class Example9 extends GenericForwardComposer {

private static final long serialVersionUID = 1L;
private Textbox firstName;
private Textbox lastName;
private Textbox address;

public void onClick$Clear(Event event) {

Important Notes in the above code.

1. The event handler must be declared as public. Otherwise, they will be ignored from auto-wiring.

Here is the demo

Here is the source code


  1. Hello,

    What is better SelectorComposer or GenericForwardComposer?



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...