Web Development | Ios and Android App Development Company in Charlotte Nc
+1 704 215 4622
[email protected]

Want Rich/Stunning Web Applications? ZK is right for you !

The first thing that came to my mind when ever I heard “Web Application” was JSP on front-end. May be I was too used to it or May be too comfortable with it. During that time I had to learn ZK for a project and the result is “I am totally smitten by it”. The rich GUI experience and easiness of coding really made me blind. This is not a starter tutorial for ZK. The ones provided in their website are too good. I am here to write about some of the note worthy aspects of ZK and some code snippets I believe would be useful for some one. I am still a newbie, So feel free to correct me or add in some valuable comments/Suggestions.

What ZK is?

ZK is an event-driven, component-based framework to enable rich user interfaces for Web

applications. ”-Definition from the creators itself.

Some stunning Features of ZK

* Rich GUI Experience

* Ability to Differentiate the Business Logic From Implementation

* Server Push Technology

* Internationalization

Rich GUI Experience

Everyone wants a rich GUI experience in their web applications. But the very need shouldn’t compromise the speed. Putting it in another way, the page should load fast. ZK includes an AJAX-based event-driven engine, a rich set of XUL and XHTML components and a markup language called ZUML (ZK User Interface Markup Language) which is not only easy to use, but also delivers a high quality GUI experience with out compromising speed.

One of the key aspect of ZK driven projects are the responsiveness of the application. At times you will scratch your head thinking whether its a desktop application!

Ability to Differentiate the Business Logic From Implementation

This one of the most important feature of ZK. It is easy to isolate the business logic completely from the User Interface. I can explain this with a simple example. I am using ZK to create a login screen which accepts user name & password from the user for authentication. First let me show you the real code and then explain how it works.

************************************Code**************************************

Login.zul

<?xml version=”1.0″ encoding=”UTF-8″?>

<div align=”center”>

<window id=”login” Title=”Login page” border=”normal”

width=”400px” mode=”modal”

use=”cyberpen.web.LoginWindow”>

<label id=”errLabel” style=”color: red”/>

<grid>

<rows>

<row>

<div align=”right”>

<label value=”User Name :”/>

</div>

<div align=”center”>

<textbox id=”username” constraint=”no empty”/>

</div>

</row>

<row>

<div align=”right”>

<label value=”Password :”/>

</div>

<div align=”center”>

<textbox id=”password” type=”password” constraint=”no empty”/>

</div>

</row>

<row spans=”2″ align=”center”>

<button label=”Login” onClick=”login.onLogin()”/>

</row>

</rows>

</grid>

</window>

</div>

LoginWindow.java

package cyberpen.web;

import org.zkoss.zul.Textbox;

import org.zkoss.zul.Window;

public class LoginWindow extends Window {

/**

*

*/

private static final long serialVersionUID = 8477939400437670121L;

public void onLogin(){

String User_Name = ((Textbox) getFellow(“username”)).getValue();

String PassWord= ((Textbox) getFellow(“password”)).getValue();

}

}

********************************End Of Code************************************

Lets see how this works. In the Login.zul file every distinct component has got a unique id. Please note that the id’s must be unique, if two components have the same id, ZK will throw an error during compilation.

<row>

<div align=”right”>

<label value=”User Name :”/>

</div>

<div align=”center”>

<textbox id=”username” constraint=”no empty”/>

</div>

</row>

As you can see the unique id for the textbox that takes the value of UserName is “username” . And We are getting this value directly in our java program. How is this possible ?

We have explicitly given in the Login.zul file that it should use the class “cyberpen.web.LoginWindow

<window id=”login” Title=”Login page” border=”normal”

width=”400px” mode=”modal”

use=”cyberpen.web.LoginWindow“>

…….

</window>

Please note that full path to the location should be explicitly given.

Now how are we reading the value from textbox?

You can see that the Login Button onClick is mapped to the function “login.onLogin()”

<button label=”Login” onClick=”login.onLogin()”/>

Please note “login” is the unique id of the window component of our zul page which is asked to use the class “cyberpen.web.LoginWindow” and OnLogin() is the method defined inside this class.

Now we use ZK’s getFellow() method to read the value of username and password and store it in seperate variables.

String userName = ((Textbox) getFellow(“username”)).getValue();

String passWord= ((Textbox) getFellow(“password”)).getValue();

where “username” & “password” are the unique id’s of the textboxes for UserName and Password respectively.

So whats the exact point?

You can give the zul page to a web designer and ask him to decorate it while the underlying logic remains the same. Web designer need not know java or worry about any underlying stuff. Put it in converse, if you want to change the underlying business logic you don’t need to change anything in the front end.

This is worry free compared to having a long jsp file with lots of java scripts, and control flowing back and forth. It will be harder to make it and more harder to redesign later.

Server Push Technology

Server push means to put content from the server to the client actively. See https://www.zkoss.org/wiki/ZK Developer’s Reference/Server Push for more details.

Is it worth Learning?

I would say “YES” . At the end of the day, the question is “Did you make something simpler and easy to use” 🙂

ZK is a sourceforge project that is growing better day by day. See : http://www.zkoss.org/

Some Improvements required for ZK

  1. The components needs to appear the same across different browsers. There are lots of hot fixes for some of the known issues please look through the ZK forum. But still there are some problems that I experienced while working on it, especially Mozilla Firefox failing to understand the height=”100%” , width=”100%” attributes.

  1. Paint support is required which is due on the next release.

Viewer comments/suggestions are welcome.

HTH,

Anoop Menon

About author View all posts Author website

anoopmenon

Leave a Reply

Your email address will not be published. Required fields are marked *