ZK vs. Ajax JSF Components: Simplicity Matters!

Jeff Liu, Engineer, Potix Corporation
May 28, 2008

Contents

  1. Abstract
  2. Innovation vs. Refinement
  3. ZK vs. ICEfaces in Action : Google Maps Locator
  4. Mobile Solution
  5. Conclusion

1. Abstract

In a previous article??ZK vs. GWT, the importance and advantages of server-centric architecture were discussed and outlined. In a server-centric approach, developers simply do their programming on the server side using Java. There is no replication of business logic on the client, no hassles of asynchronous programming, and no hazards of exposing business logic on the client.

More and more Ajax frameworks are adopting this architecture, e.g. ZK, Backbase, Richface and so on. In this article, ZK will be compared against one of the 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 its server-centric architecture and event-driven model, developing web applications with ZK becomes as intuitive as programming desktops. With 170+ Ajax components and a mark-up language, designing rich user interfaces becomes as simple as authoring HTML pages. Without declaring each managedbean in configuration, ZK provides a more flexible and dynamic mechanism to achieve data accessing, annotation-databinding and variable-resolver. In recent releases of ZK, developers can even bind Java Beans into an Ajax spreadsheet application. This technical breakthrough will bring a new age to web applications development.

To learn more about how ZK works as a server-centric framework, refer to the following: Also, for migrating page-based JSF to Ajax JSF, ZK offers 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 phase rather than the standard JSF approach of rendering all of the DOM tree. From this point, ICEfaces? Ajax Bridge, which is a mechanism to communicate between client and server side will modify the DOM tree on the client side asynchronously. As a result, an ICEfaces application still needs to go 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 by ICEfaces in order to demonstrate the difference between the frameworks.  Assume that you are coding a Google Maps Locator for a client, given the following  requirements:

  1. An UI with a text input field, a button and a Google map.
  2. 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.
  3. Display the location on the Google Map and display the description as an Info Window.

Figure.2 - Google Maps Locator

Let us assume you have already implemented a magical Java class called ?ocator??which takes a string as input and returns 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&amp;v=2&amp;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>
	

Adopting the Direct RIA architecture, ZK is a 100% event-driven model which decouples user interface from business logic. From the above code, 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 to 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; charset=iso-8859-1"></meta>
	<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-phase 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 the wrapper for saving the latitude and longitude of current center?

From the 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 that is easy to learn and fast to develop with? I don’t think so. In my personal experience, if you are not familiar with JSF or if a 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 devices. But, the problem is that they are limited by browsers 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 of ZK brings benefits to those resource constrained devices. Your client devices will not be limited to robust ones with a browser. With ZK, you can run your Web applications anywhere without device resource restriction.

ZK on Java Phones

Figure 3 - ZK on Java Phone

More articles about ZK Mobile

ZK on Google Adroid

Figure 4 - ZK on Android

More articles on ZK Android

5. Conclusion

Simplicity Matters!

Compared to ZK, ICEfaces is more like a JSF components set than an Ajax framework. This shows that Ajax JSF componenets such as ICEfaces don't get rid of the JSF complicated lifecycle and configuration issues. For those who already are JSF experts, Ajax JSF solutions like Richfaces and ICEfaces might be a needed painkiller for adding Ajax to projects. But, not for those who are tired of JSF and are looking for a new Ajax solution that does not suffer from the difficulty of customizing components and the complicated configurations.

“Comparing to JSF, ZK is on a whole new level.”
-Daniel Seiler, COO of processwide

From the above, one can conclude that compared to JSF, ZK is much easier to learn because of its intuitive programming style. I believe that JSF is a well-defined standard. But, it is designed for the time when people designed applications using a "page-based" pattern. When Ajax emerged and became the must-have, the time was ripe for next generation web application frameworks. Ajax is simple, but people insist on making it complicated. about the next generation web application frameworks. Ajax is simple, but people insist making it complicated.

Comments
 
ZZ TOP
2008-05-28

There is no doubt that ZK is one of the simplest web development frameworks around. It is simpler than any other Java web framework. But the only question I have is whether ZK is appropriate for a web-site that expects millions of visitors every day?? Will ZK's architecture not work on such large sites because of the huge amount of memory required on server? Also, how is ZK's performance compared to Wicket/Tapestry/Seam? With ZK, making the back button work (easily) and the "open in new tab", and bookmarkable URLs also appear to be potential problem areas?

Marcos de Sousa
2008-05-28

Good question ZZ TOP.

Well, you could test performance comparing Wicket with ZK for example, then publish to us the result you found.

About "With ZK, making the back button work (easily) and the "open in new tab", and bookmarkable URLs also appear to be potential problem areas?" Remember that ZK is to programming like DESKTOP application. On the other hand you coud use traditional redirect then all your bookmarkable, back button url will work isn't it?!

Jeff Liu
2008-05-29

Beside the performance issue, supporting and development efficiency are more critical issue. There are many solutions to the performance issue like clustering , distributing databases, and etc. But, it is difficult to get suitable support to beat the deadline. I believe in that the most important issue is about "PEOPLE." From my personal experience, get a framework which comes with expertise and on time support is more important than others. ZK did a good job on this!

Alex
2008-05-29

To Marcos :

Some have the same arguments than you for their framework regarding desktop approach (like people from qooxdoo for example) but while i agree with you on the fact you want ZK works this way which i imagine is fine for your applications and needs, i completly disagree on using this thinking as a reason for not making some things possible.

First because making these things are possible (combining traditional web approach + desktop approach at the same time), and second because some do it (like people from Backbase wich is not the only example by the way).

If ZK don't manage the adequation of the 2 approachs at the same time, it's a choice regarding what kind of applications zk developers want to build with and absolutely not a good reason for telling something close to "zk can't do it so the 2 approachs can't be combined together" which is not far from a nonsense.

Alex
2008-05-29

As another examples similar to Backbase, i have memories that Jackbe and smartclient are also capable to do such things, so have to verify this information for these 2 ones but i think they are also good example in this area if i remember well.

Alex
2008-05-29

I forgot to mention the third reason (which is fact the main one) : some applications really need it, it is not a fancy need.

As it's possible, i see this as an advantage over others technologies approach for which your arguments are closer to something true (i think here of such things like flash in the ria world for example)

Akai
2008-05-29

To Alex
"combining traditional web approach + desktop approach at the same time" is great point. I believe you can achieve both approaches by ZK. I would like to answer you guys a question.

Why people do not use ZK? It is interesting question.

ZZ TOP
2008-05-29

I did not mean to start this discussion as a criticism of ZK. In my opinion, ZK is certainly the easiest of any web development framework. Also, with ZK you get other advantages - such as not having to bother with css as the default styles of the components are very attractive. Javascript is obviously not required.
However, based on my experience, the traditional redirect is a little more difficult (and slow) to do in ZK than in other frameworks like Tapestry 5.
So, if I want to build a website which expects millions of visitors, then I will use Tapestry 5 (that is the second easiest framework to use after ZK). If I am building a business application with only hundreds of users, I would go with the ZK desktop solution as it is very easy and the default components are very attractive.

Alex
2008-05-29

To Akai
Not so easy to answer your question. To my mind, if we want to go along a pragmatic and realistic answer, we could think around the first question that could be : are people using ZK ? So, it seems obvious you know more than me on this subject as your question is one step further :).

On the other, that's true there are not as much talks on zk as many other web desktop frameworks, in fact far from it but it's just a part of the question and that may change as zk developers do great job and allow zk to improve rapidly along a continuous development effort. One consequence for example is their zk seam which should participate in a very good orientation that will make zk more popular (jboss platform, jboss seam, jbpm and so on are regularly under the spotlights as excellent references). At least, i hope work on zk seam will continue as an important branch of the zk team priorities. Waiting for Seam 2.x support by the way.

This being said, i think there are still some important points which disadvantage ZK. To my mind, the most obvious is the licence, GPL for a framework is quite problematic to say the least :). While i understand the zk team arguments, i think an effort could be clearly made without changing the licence on a general point of view.

Explanations : take a look on the licence thread subject on sourceforge and particulary this one : http://sourceforge.net/forum/message.php?msg_id=4846291

ZK team follows the pure basic logic saying that they need at least a little money to live so they can't give everything as a gift. There is 0 possibilities i can't agree with this :) so i follow the same logic as the one exposed in the thread conclusion: "I think the principle of fair exchange is respected here, i collaborate with opensource communities and i also, like you, just would like to feed my children too." which means that we also can give things to ZK but not everything as even us have the right to live :). For the others that are in a commercial context and do not contribute to zk, they just have to follow the commercial packages.

I think this thing would make zk a little more attractive (and for me a lot more :) ).

Chic
2008-05-30

ZZ TOP: "...With ZK, making the back button work (easily) and the "open in new tab", and bookmarkable URLs also appear to be potential problem areas?"

As my understanding, ZK has supported back button and bookmarkable URL since version 2.xx. See

http://www.zkoss.org/doc/devguide/ch10s05.html

And to open in new tab, just call

Executions.getCurrent().sendRedirect(newURL, "newTarget") ;

See
http://www.zkoss.org/javadoc/3.0.0/zk/org/zkoss/zk/ui/Execution.html

Mike
2008-05-30

ZK supported bookmark long time ago. Actually, petshop and the upcoming forum use bookmark, too.

ZZ TOP
2008-06-05

After using ZK and Tapestry 5 for the past few weeks, I can say with confidence that ZK is far simpler. Tapestry 5 is simple compared to other frameworks, but it is highly unstable at this time (beta), and the documentation is nowhere close to what ZK has. One of ZK's biggest strength is the excellent documentation (although a few more books would help). Also, if you want to do nice AJAX with Tapestry 5, it is much more work compared to ZK.
I don't know how to do a speed, memory, cpu comparison between ZK and the other leading frameworks (JSF, Struts, Wicket etc), but if someone can do that comparison and post the results, it will be very helpful. Already, in terms of usability, features, and developer productivity, ZK is way ahead of others.

Matthias Wessendorf
2008-06-06

Ridiculous !
#3 compares apples and oranges...

ZZ TOP
2008-06-07

I don't know what is so ridiculous about comparing ZK with Icefaces. It is a very good comparison, and shows the ease of ZK. In my opinion, the people who use JSF and IceFaces are so used to complexity that they cannot understand how ZK could be so simple. I agree that GPL license is probably holding back ZK's popularity, but the developers need to make some money, otherwise they cannot continue to improve this at such a rapid rate.

Jeff Liu
2008-06-17

Hello ZZ TOP

Do you want to share your experience with Tapestry and ZK? please contact me at jeffliu@zkoss.org

nick
2008-06-18

What I fail to see, is how to bind a Backing Bean to ZK Components. This is one of the prolems I have with this Implementation.

Anyways, I had very bad experience with ICE Faces and its Navigation and don't see myself using them in the futhure.

nick
2008-06-18

By the way, what I also miss in ZK is the Data Table, or is it has to be one of the list boxes?

thanx in advance.

Jack
2008-06-25

As I know, ZK provides a kind of annotate data binding which allows you to data bind beans automatically. As for the Data Table, the grid and listbox component both support a ListModel mechanism that you can manipulate data directly and the view will reflect the data changes automatically. Their tech articles (smalltalks) talks a lot of such things.

nick
2008-06-27

Hi jack, thanx for the reply.

Ever since I posted above, I use RichFaces, which I find enough for my needs of AJAX binding in my JSF.

What I don't like about both ZK and RichFaces is the lack of Tutorials, but since RichFaces is for Free, I don't mind, I find my way around it.

Thanx you anyway

simon
2008-08-08

I have been using ZK for two years in a fortune 500 financial organisation. Folks time and time again people tried to tell our team doing it 'ajax will slow the network, zk will be too memory intensive'. All the time it was simply bad guesses. They never considered that a "full page rebuild" of a normal site sends a lot of traffic (just to update a tiny piece of the page) and that memory is in fact dirt cheap and zk is quite efficient in space. Lots of money has been spent performance testing zk. And the answer to the performance question is that the overhead really isn't anything much. It depends of course on how you wrote you app and arranged your UI and which ZK techniques you used but there seems to be no measurable "tax" for our systems for using ZK. There is on big difference though. At this fortune 500 company we normally task 2.5 or 3 webapp developers for every one spring/back-end developer when using traditional full page technologies such as struts/jsf. With the team using ZK though we don't need 3 people we only need one person implementing screens. So the team using ZK builds web applications three times after than the teams that use struts. Another point to make is that the comments here talk about putting 1 million users on a single server. Here at this fortune 500 company we have seven multiprocessor servers for just 1500 users of an older j2ee application using early EJB2. These days a zk/pojo/spring application would do that many people on all the number of servers so long as the database design was good which we typically find is the constraining factor to load testing - it certainly is not the web framework. The web framework only constrains your programmer productivity.

 
 
Leave a Reply
 
Name (required)
Mail (will not be published) (required)
Website
(Case Insensitive)
Bold textItalic textUnderLine textSource CodeHorizontal rulerExternal Link
Post
Preview