Tuesday, 24 April 2012

ZK MVC Using .GenericAutowireComposer utility class


This is the third post in a series of ZK MVC



I am just following the zk documentation and creating another sample 
here is the ZK Documentation url



Before this, summary of the previous post is

We started with Composer 
http://emrpms.blogspot.in/2012/04/mvc-using-composer-interface.html

Then we removed all the event listeners and it is done by zk automatically by  genericcomposer utility class

http://emrpms.blogspot.in/2012/04/zk-mvc-using-genericcomposer-utility.html

Now we will see how we can remove all those binding using getfellow methods. This can be done
using org.zkoss.zk.ui.util.GenericAutowireComposer utility class which extends GenericComposer class and add the auto-wire features

Here is my zul code

<?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.GenericAutowireComposer"
style="font-size : 18px;font-family: verdana,arial,sans-serif;" />
<separator />
<window title="MVC Pattern using org.zkoss.zk.ui.util.GenericAutowireComposer" border="normal" width="700px"  apply="com.me.Example8">
<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 java file


package com.me;


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


@SuppressWarnings("rawtypes")
public class Example8 extends GenericAutowireComposer {


private static final long serialVersionUID = 1L;
private Textbox firstName; //auto-wired
private Textbox lastName; //auto-wired
private Textbox address; //auto-wired


//all getFellow() codes are removed

public void onClear_btn(Event event) {
firstName.setValue("");
lastName.setValue("");
address.setValue("");
}
}

Again here is the source code and demo
http://zkfiddle.org/direct/3hjk8af/5/v6.0.0-MVC-Using-GenericAutowireComposer?run=3gbaqbu

In the next post, we will see how to Get Rid of Those "forward" Attributes
using GenericForwardComposer



No comments:

Post a Comment