ZK vs. Ajax JSF Components: Simplicity Matters!
Contents
|
1. Abstract
From the previous article¡X ZK vs. GWT, the importance and advantages of server centric architecture were discussed and outlined. By server-centric approach, developers simply do the programming on the server side using Java. There will be no replication of business logic on client, no hassles of asynchronous programming, and no hazards of exposing business logic on client.
There are more and more Ajax frameworks adapt this architecture like ZK, Backbase, Richface and so on. In this article, ZK will be compared with one of Ajax JSF components sets-ICEfaces.
2. Innovation vs. Refinement
ZK - Innovation:
ZK is an open-source Ajax framework which enables Java developers to create rich Web applications with little programming. With the server-centric architecture and event-driven model, developing Web applications becomes as intuitive as programming desktops. With 170+ Ajax components and mark-up language, designing rich user interfaces becomes as simple as authoring HTML pages. Without declaring each managebean in configuration, ZK provides more flexiable and dynamic mechanism to achieve data accessing, annotation-databinding and variable-resolver. In recent releases of ZK, developers can even bind Java Bean into an Ajax spreadsheet application. This technical breakthrough will bring a new age to web applications developing.
To Know more how ZK works as a server-centric framework, refer to the following: Also, for migrating page-based JSF to Ajax JSF, ZK offer its own JSF components set. Refer to:
ICEfaces - Refinement:
ICEfaces is a components set for JSF. More than 50 Ajax components for JSF are supported by ICEfaces. As ICESoft mentions in the ICEfaces document, Icefaces framework is only an extension of standard JSF. It is still a traditional page-based architecture. The key difference is that ICEfaces only render the incremental changes in the rendering phrase rather than the standard JSF approach¡Xrender all DOM tree. From this point, ICEfaces's Ajax Bridge, which is a mechanism to communicate between client and server side will modify the DOM tree in client side asynchronously. As a result, the ICEfaces application still needs going through the standard JSF lifecycle.
3. ZK vs. ICEfaces in Action : Google Maps Locator
In the following section a simple Google Maps Locator application will be implemented by ZK and ICEfaces in order to demonstrate the difference between the frameworks. Assuming that you are coding a Google Maps Locator for a client, the requirements might contain:
- An UI with a text input field, a button and a Google map.
- When user clicks the button the text in the textbox will be used as a keyword to find the latitude, longitude and description for that location.
- Displaying the location on the Google Map and display the description as an Info Window.
Let us assume you have already implemented a magical Java class which is called "Locator." It will take a string as input and return the required information. The only work left is implementing the UI and data retrieval parts. Let's see code from both frameworks in real action.
ZK (1 File, 36 Lines of Code)
Gmap.zul:
<?xml version="1.0" encoding="utf-8"?>
<zk>
<script src="http://maps.google.com/maps?file=api&v=2&key=KEY"
type="text/javascript">
</script>
<zscript>
import com.macroselfian.gps.Locator;
public void locate(){
String location = tb.getValue();
double[] pos = Locator.locate(location);
mymap.panTo(pos[0], pos[1]);
mymap.setZoom(16);
ginfo.setOpen(true);
ginfo.setLat(pos[0]);
ginfo.setLng(pos[1]);
ginfo.setContent(Locator.getInfo(location));
mymap.openInfo(ginfo);
}
</zscript>
<window>
<div align="center">
<separator spacing="50px" />
<vbox>
<label value="Macroselfian Google Map Locator"/>
<hbox width="600px">
<textbox width="550px" id="tb"/>
<button width="50px" onClick="locate();" label="Search"/>
</hbox>
<gmaps id="mymap" zoom="16" ...>
<ginfo id="ginfo"/>
</gmaps>
</vbox>
</div>
</window>
</zk>
Adapting Direct RIA architecture, ZK is 100% event-driven model which decouples user interface from business logic. From code above, 3 advantages of Direct RIA architecture can be found.
First, developers directly access data without extra backing beans; this offers a more intuitive approach than JSF backing beans.
Second, no extra configuration for each component and controller. It gives developers more flexiblity than traditional page-based application.
Last, ZK offers the zscript element which allows developers script in Java directly on the zul file. By scripting in zscript, developrs directly manipulate components, EJB beans, Java Beans, or even the variables from JRuby interpreter, the interaction within components becomes a straight-forward task.
Icefaces (3 Files, 223 Lines of Code)
Jspx Page:
- gmap.jspx
Java Bean:
- LocatorBean.java
JSF Config File:
- faces-config.xml
Code Snippet:
gmap.jspx:
<f:view xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component">
<ice:outputDeclaration doctypeRoot="HTML"
doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN"
doctypeSystem="http://www.w3.org/TR/html4/loose.dtd" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; /> <link href="xmlhttp/css/xp/xp.css" type="text/css" rel="stylesheet">
<style>
.iceGmp {
}
.iceGmpMapTd {
vertical-align: top;
}
.iceGmpMapTd div.gmap {
width: 800px;
height: 600px;
}
</style>
</link>
</head>
<body>
<ice:form>
<ice:outputConnectionStatus />
<ice:inputText value="#{locator.location}" width="200px"
partialSubmit="true" />
<ice:commandButton type="submit" value="Submit" />
<ice:gMap latitude="#{locator.lat}" longitude="#{locator.lng}"
zoomLevel="16">
<ice:gMapControl id="largectrl" name="GLargeMapControl" />
<ice:gMapControl id="scalectrl" name="GScaleControl" />
<ice:gMapControl id="typectrl" name="GMapTypeControl" />
<ice:gMapMarker id="gmarker">
<ice:gMapLatLng id="glatlng" latitude="#{locator.latMark}"
longitude="#{locator.lngMark}" />
</ice:gMapMarker>
</ice:gMap>
</ice:form>
</body>
</html>
</f:view>
LocatorBean.java:
package com.macroselfian.gps;
public class LocatorBean {
Locator _locator;
String _lng ="0.0";
String _lat ="0.0";
String _lngMark ="0.0";
String _latMark ="0.0";
String _title ="";
String _info ="";
public String getLocation() {
return _locator.getKey();
}
public void setLocation(String location) {
_locator = new Locator(location);
_lng = _locator.getLng()+"";
_lat = _locator.getLat()+"";
_lngMark = _locator.getLng()+"";
_latMark = _locator.getLat()+"";
_title = _locator.getTitle();
_info = _locator.getInfo();
}
public LocatorBean() {
setLocation("");
}
public String getLatMark(){
return _latMark;
}
public void setLatMark(String lat){
_latMark = lat;
}
public String getLngMark(){
return _lngMark;
}
public void setLngMark(String lng){
_lngMark = lng;
}
public String getLat(){
System.out.println("getLat"+_lat);
return _lat;
}
public void setLat(String lat){
System.out.println("setLat");
_lat = lat;
}
public String getLng(){
return _lng;
}
public void setLng(String lng){
_lng = lng;
}
public String getTitle() {
return _title;
}
public void setTitle(String title){
_title = title;
}
public String getInfo() {
return _info;
}
public void setInfo(String info){
_info = info;
}
}
faces-config.xml:
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
...
<managed-bean>
<managed-bean-name>locator</managed-bean-name>
<managed-bean-class>com.macroselfian.gps.LocatorBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<!-- -->
<application>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
...
</faces-config>
Icefaces inherits burdens from traditional page-based JSF. As a reault, ICEfaces developers use JSF's backing bean concept, and the 6 phases lifecycle. But, as mentioned above, developers need to be familiar with the controversial JSF lifecycle and backing bean concept in order to painlessly deal with ICEfaces. From the above example, an additional wrapper bean class is needed for wrapping the magical locator class. At first, it is confusing for a developer who is new at JSF. For example, should I add an additional pair of coordinates to wrapper for saving the latitude and longitude of current center?
From above, one can easily tell that ICEfaces only solves the "richness" issues of JSF. It is still necessary for developers to understand the 99% of JSF concept. Does it do any good to a web application developer who wants a framework is easy to learn and fast develop? I don't think so. In my personal experience, if you are not familiar with JSF or the legacy application is not designed with JSF JavaBean concept, ICEfaces won't be a painkiller; it will be another trouble maker.
4. Mobile Solution
What about the devices without browsers?
Many Ajax JSF frameworks support mobile device. But, the problem is that they are limited by browswers in smart phones. What about 1.8 billion Java phones which do not come with such resources (computing power, memory, browser, etc.) that iPhone provides? The server-centric/thin-client approach by ZK brings benefits to those resource constrained devices. Your client devices will not be limited to robust ones with browser. With ZK, you can run your Web applications anywhere without device resource restriction.
ZK on Java Phones
More articles about ZK Mobile
ZK on Google Adroid
More articles on ZK Android
- Extend your Web Application to Android - An Example of Google Calendar
- A Preview of ZK Mobile for Android
- Win Android $10 Million Developer Challenge by ZK Mobile for Android ;-)
5. Conclusion
Simplicity Matters!
Comparing to ZK, ICEfaces is more like a JSF components set than an Ajax framework. This tells that Ajax JSF componenets such as ICEfaces doesn't get rid of the JSF complicated lifecycle and configuration. For those who already are JSF experts, Ajax JSF solutions like Richfaces and ICEfaces might be painkiller for adding Ajax to projects. But, for whose get tired of JSF and look for a new Ajax solution suffer from the difficulty of customizing component and its complicated configuration.
-Daniel Seiler, COO of processwide
From above, one can conclude that comparing to JSF, ZK is much easier to learn by its intuitive programming style. I believe in that JSF is a well-defined standard. But, it is designed for the time when people design application by "page-based" pattern. When Ajax emerges and becomes the must-have, probably it is time to consider about the next generation web application frameworks. Ajax is simple, but people insist making it complicated.
- Login or register to post comments
- 2916 reads
- Email this Article
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)







Comments
Fred Barney replied on Thu, 2008/07/03 - 10:51am
"Icefaces (3 Files, 223 Lines of Code)"
Oh good grief. 223 lines counting the 94 lines out of 157 in LocatorBean.java that are empty. Is this article also going to have a bunch of astroturfy comments like the last one?
Jacek replied on Thu, 2008/07/03 - 10:51am
So, you are embedding Java code in an XML file:
and attempting to tell tme that this is a better solution that having it in a .java file? I have a hard time believing in that.
I am not saying here that JSF/ICEFaces is the best thing since sliced bread, but your code above makes me worried that this type of approach will be tough to support once you get to any form with some serious, complex UI logic that goes beyond 10 lines of code.
Robert O'Connor replied on Thu, 2008/07/03 - 11:45am
madruga0315 replied on Thu, 2008/07/03 - 12:32pm
The java code inside xml is good for prototype, because .zul file does not need compilation. So changes in .zul are reflected automaticly in your web, so you don´t need to restart the server, and depending how you developede, you don´t need event to refresh the page, only that parte that was changed.
After you prototype, the best approach is to remove all Java codes from xml and put in a Java class, and wire you zul page with that class.
Another point for using Java inside zul from files published in the web, is that you don´t need to create the files in your machine, just copy then and run in ZKdemo site to test it.
http://zkoss.org/zkdemo/userguide/
Kimmig replied on Thu, 2008/07/03 - 12:32pm
Could somebody please stop those stupid "ZK vs abc" comparison blog posts?
They are so extremely biased and a huge source of incompetence and misinformation, it does not deserve to be here.
I remember the last flame episode, I think it was ZK vs GWT where at one point the author said something like "and the example in GWT... Dude, I dont even wanna code it". Need I say more?
Shashank Tiwari replied on Thu, 2008/07/03 - 4:02pm
@Kimmig: Everybody has a right to their opinion. Just as you have the right to express opposition to the article, the article author has the right to claim that his/her viewpoint is correct. The reason for the existence of numerous technologies, languages and specially frameworks is that there isn't one that solves all the problems or is universally liked. People are passionate about what they create. The author is one of the creators of ZK. ZK incidentally was the most downloaded Ajax framework on Sourceforge last year.
Instead of stopping others, I invite you to express your opinion freely through your own stories and articles. Why not write something positive -- say "abc has xyz nifty features" or even counter this post with a story "abc vs ZK" and show that abc is better. I will be happy to get that online.
As dzone we are a neutral platform and respect everybody's opinion. By publishing this article, we are not in any way saying that we like or dislike ZK.
Thanks....Shashank
Zone Leader
Kimmig replied on Thu, 2008/07/03 - 4:46pm
in response to: sandbox
Fine, I am sorry if I expressed my opinion too offensively, but especially from the creator of a framework I expect a fair comparison.
Steven replied on Thu, 2008/07/03 - 5:09pm
jebberwocky replied on Thu, 2008/07/03 - 8:23pm
in response to: fb43282
Hi Barnery,
I'll fix the empy part. thx for your correctness. but besides it, would you like to point out which part of this article makes you feel astroturfy? I will be glad to hear different voices. thx!
jebberwocky replied on Thu, 2008/07/03 - 8:31pm
in response to: Jacek
Hi Jacek,
Actually, ZK supports both of scripting languages, and java codes. the choice is yours.
jartender replied on Thu, 2008/07/03 - 9:55pm
in response to: jebberwocky
I haven't used ZK before, this is a great opportunity as I can ask the architect of ZK himself. Kindly provide us more info on the following:
1) The performance of ZK vs. JSF/IceFaces and ZK vs GWT (guys like me doesn't care much about the lines of codes - and the guys who prefer not being called back to check why the application is slow after it has been deployed).
2) The scripts that you put or trigger inside the zul file, they are being executed in the server right? Does ZK have some mechanism that it can actually convert the embedded java into a javascript during development and execute the javascript on the client side once it is already being used? (one of the features that I really like about GWT)
3) In ZK, how do you control the "scope" (session or application) of the java codes you call inside the page? Does ZK instantiate a different set of all the objects it needs every time that there is a new session? or everytime that there is a request? It is important as we want to reuse objects as much as possible. In JSF, you can actually control the scope of the managed bean and have the complete control of it.
Thanks.
jebberwocky replied on Fri, 2008/07/04 - 1:38am
in response to: jartender
1. Good idea! This is an intersting topic, we'll try to investigate this issue.
2. Yes, those scripts run on server side. And, no, ZK doesn't convert Java into JavaScript. With ZK, developers can do a lot of things in pure Java, and ZK allows developers to invoke JavaScript functions in Java codes. Would you like to point your requirements?
3. Yes, ZK is session based, and ZK provides great integration with Spring and Hibernate. Thus, there is no problem if develpers want to control the scope of beans. Please take a look at the following url,
http://www.zkoss.org/smalltalks/hibnsprn/hibn_sprn_zk.html
http://www.zkoss.org/smalltalks/springdao/sdao.html
thx!