Tuesday, 24 April 2012

ZK MVC An Annotation Based Composer For MVC


Finally , we will end using zk 6 An Annotation Based Composer For MVC
This is the 5th post in a series of ZK MVC
Here is the zk documentation and we are following that
and creating new example
http://books.zkoss.org/wiki/Small_Talks/2008/August/ZK_MVC_Made_Easy
http://books.zkoss.org/wiki/Small_Talks/2011/January/Envisage_ZK_6:_An_Annotation_Based_Composer_For_MVC



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
events

Here is the Link for the first post
http://emrpms.blogspot.in/2012/04/mvc-using-composer-interface.html


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
http://emrpms.blogspot.in/2012/04/zk-mvc-using-genericcomposer-utility.html

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

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

Method 4: extends GenericForwardComposer
Here, we removed forward attributes using GenericForwardComposer utility class
Here is the link
http://emrpms.blogspot.in/2012/04/zk-mvc-using-genericforwardcomposer.html



Finally we will the same output using zk 6 An Annotation Based Composer For MVC

A composer analogous to GenericForwardComposer. Instead of wiring variables and adding event listeners by naming convention, this composer do the work by annotation and selectors.

Here is my zul code

<?page title="Example10" contentType="text/html;charset=UTF-8"?>
<zk>
<label
value=" http://books.zkoss.org/wiki/Small_Talks/2008/August/ZK_MVC_Made_Easy.
http://books.zkoss.org/wiki/Small_Talks/2011/January/Envisage_ZK_6:_An_Annotation_Based_Composer_For_MVC"
style="font-size : 18px;font-family: verdana,arial,sans-serif;" />
<separator />
<window
title="MVC Pattern An Annotation Based Composer For MVC"
border="normal" width="700px" apply="com.me.Example10">
<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" />
</row>

</rows>
</grid>
</window>
</zk>


Here is my composer
package com.me;


import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

public class Example10 extends SelectorComposer<Window> {

@Wire
private Textbox firstName;
@Wire
private Textbox lastName;
@Wire
private Textbox address;

@Listen("onClick=#Clear")
public void submit() {
firstName.setValue("");
lastName.setValue("");
address.setValue("");
}

}


Here is the demo
http://zkfiddle.org/direct/cqjvuo/2/v6.0.0-MVC-An-Annotation-Based-Composer-For-MVC?run=3gbaqbu

Here is the source code
http://zkfiddle.org/sample/cqjvuo/2-MVC-An-Annotation-Based-Composer-For-MVC

No comments:

Post a Comment