Boost Your Productivity Using Apache Tapestry

13 09 2008

If you are like me, you really don’t have time to waste with frameworks that suffer from favoring “elegance of design over everything else”.. take the old EJB model as an infamous example.

Personally, all what I care about is finding new ways to improve productivity. Nowadays, I prefer frameworks and APIs that are designed for simplicity of use in the first place. You invest some time and effort, and gain back generous increases in productivity.

If you’re into Java-based web applications, you probably know how challenging it is to develop the UI Layer of the application — while keeping View code clean (readable) and neatly separated from back-end code.

That’s why a number of months ago I decided to go on the hunt for the ultimate UI framework — if it ever existed. I pictured a framework where complexity of handling UI events and moving data back-and-forth between Model and View is hidden from the developer, such as with desktop applications.

I enumerated a number of frameworks from I did not consider some excellent technologies such as AdobeFlex and another framework called ZK (watch out for that one) just because you do not write the interface in HTML or any close markup, but rather in completely different proprietary language.

I also ignored frameworks that do not have an online demo. Presence of an online demo is the least thing framework owners should offer to their prospective users… lack of an online demo gives me negative vibes about the health of a UI technology.

I ended-up looking at a couple of JSF implementations, Apache Tapestry, and Apache Wicket based across several dimensions:

  • Learning Curve
  • Maturity (which reflects on other traits such as reliability, security, and performance)
  • Programming Model
  • AJAX Support

The following are the results of my quick research. This is not an extensive research, with anything but concrete results. I was in a rush (as always!). I just brushed over the surface, with high reliance on first impressions and short test drives. Use the results with caution!

I easily ruled out JSF. I got the impression that it was plagued with the same “elegance of design over everything else” virus that used to plague Java specs (the situation is getting better now). As usual, JSF needs tedious XML configuration. Plus, web pages are written in JSF markup which is a turn-off to me. Yes, I don’t care that JSF is a specification.

There was a number of open-source implementations: Apache MyFaces and IceFaces. Only IceFaces seemed to be mature and impressive enough anyway. The documentation of IceFaces was far from complete or accurate, and it seemed to me that in addition to the learning curve of JSF, there will be another trickier learning curve mounted over it… to learn the “secrets” and internals of IceFaces (that was with version 1.5 as I recall, now I’m seeing a version 1.7 so perhaps things have changed).

What really clicked with me were Apache Tapestry and Apache Wicket. There is some similarity between them; they are both “component-based” frameworks that map parts of the UI in the HTML pages 1-to-1 to Classes and Objects on the server. Component-based frameworks are far more easier to deal with than JSPs and other frameworks that expose the cycle of request/response handling (such as the old Struts). Tapestry hides the request/response handling cycle pretty neatly.

So, I gave Tapestry a try. Although the documentation is not the best that they could offer, it is very extensive. The quick-start guides delivered a really quick start. I actually was able to write a simple application in a couple of hours, and boy, I was impressed with Tapestry’s potential. We’re talking super-productivity here once you get over the initial (relatively shallow) learning curve. Add to that the following great advantages:

  • You write your Web Pages in pure HTML (now XHTML with Tapestry 5)… Tapestry’s markup is elegantly hidden within HTML markup.
  • Moving data from your business logic to the web UI and back is as easy as populating and extracting data from POJOs using setters and getters.
  • Built-in AJAX support, DOJO and Scriptaculous are integrated.
  • It is easy to build your own components and extend the framework.
  • Page navigation is easy and intuitive… no need for lengthy XML files as in JSF.
  • Persisting data into a Session is a matter of calling a “set” method on an annotated POJO field.
  • Tapestry adopts the convention-over-configuration philosophy. No piles of XML configuration files, just put the jars in your Lib directory, add a couple of entries in your Web.xml, and everything just works.

After I experienced Tapestry, I was quite impressed and decided to skip Wicket and get started with Tapestry immediately. Tapestry and Wicket are more or less similar, only Tapestry is more mature. However, Tapestry has its flaws as well, ones that I recognized when I got up close and personal with the framework. So, if you decide to use Tapestry, be ready to live with the following issues:

  • First, you have to decide which Tapestry version to use. 4.x and 5.x are completely different and there is no backward compatibility. 5.x has been in “beta” stage for a long time now, but as far as my experience goes, it is stable. 5.x is far more simple than version 4.x due to its streamlined design and the use of Annotations.
  • The documentation on the website is extensive and sufficient… but as soon as you start meeting more complex scenarios, things start to get a little darker… and in some cases, you might need to do the occasional dive into the internals of the framework to understand how things work.
  • Tapestry 4.x is not satisfactory on the performance side due to the design of its request/response handling cycle. 5.x is much better on the performance side.
  • For some reason, the releases of Tapestry are few and far in between. I don’t know why. That framework has lots of potential.
  • The only book on Tapestry covers 5.x and seems to be significantly outdated. Many of the book’s examples are obsolete and do not work with the latest release of 5.x. So that brings us back to rely on online documentation.

Bottom line: Tapestry is a great framework that boosts productivity, a framework that has been elegantly designed and written for the sole purpose of making your life easier. The cons of Tapestry can be lived with, and the framework’s clean design makes it easier to understand its internals. You’ll enjoy working with Tapestry. Kudos to the Tapestry Project team.