In this article we'll begin by taking a look at servlets and JavaServer Pages, then proceed to learn about the MVC design pattern. After examining the problems these technologies solved, we'll focus on the Tapestry framework, study its advantages, and dispel some prejudices about it. This is the first article in a multi-part series covering Tapestry.
The First Reason: Tapestry is easier to learn than any other contemporary framework. I hope you will appreciate this following my tutorials. This is because the higher level architecture of Tapestry is natural and clear. Every page of a Tapestry application is a Java class. It can have its state - properties - and its behavior - methods. Pages can handle different events as they have event listeners for them.
This sounds very familiar to everyone who has done object-oriented programming, regardless of programming language. This is why Tapestry should be easy to adopt by a wide range of programmers coming from different platforms. In fact, my colleagues with an ASP.NET background find Tapestry easy to understand - but not Struts.
The Second Reason: Tapestry has a unique display technology. For example, with JSP, when you take an HTML mock up and convert it to a dynamic page, this process is irreversible. Something, which was only recently a design masterpiece, becomes, at least from the designer's point of view, a bunch of incomprehensible tags. And if there is any significant change in design, it might be simpler to throw away the existing JSP page and to create it anew.
Let's consider an example. Here is how a designer would create a simple text box:
<input type="text" class="someStyle"/>
To make this text box a dynamic part of his application, a Struts developer would write something like this:
The difference is obvious: the Tapestry template remains a valid HTML page and can be easily previewed by any standard tool, or any Web browser. To convert an HTML element into a Tapestry component, all we need to do is insert a special jwcid (Java Web Component ID) attribute. Any piece of software that doesn't know what this attribute means will simply ignore it.
One of the benefits of this is that a Tapestry template remains perfectly editable by any design tool, without a danger of breaking any Tapestry instrumentation. You will appreciate this when, after creating a few dozen pages for the first iteration of your project, you receive feedback from your client saying that design and layout should be changed in, say, 36 places. With Struts, that would be a disaster. With Tapestry, this is no problem at all.
Also, if you start your project from a series of HTML mock ups created by a designer, it takes very little effort to convert mock ups into Tapestry templates.
All in all, the Tapestry's unique display technology makes Java Web development much more efficient and solves the problem with which JSP technology has been struggling for years.
The Third Reason: Tapestry custom components are very easy to create and use. Again, Tapestry is unique in this respect between contemporary component-based frameworks. For example, in JavaServer Faces to create a component you need to know intimately the inner (quite complicated) structure of the framework. This is a task for an advanced developer, not a beginner.
In Tapestry, we shall start creating custom components in one of the first parts of this tutorial and you will see how easy it is. As soon as you see a repeating piece of the interface or functionality, you just put it into a component and then drop that component onto any page where it is needed. If you think that your components will be useful in a different project, or maybe you want to make a present for your friend, you can easily pack them into a library and distribute as widely as you wish.
This is especially important because, as perhaps is true with every framework, Tapestry has some obvious simple components missing. But that is no problem at all - create them yourself and share them with the others. This is one of the things we are going to do later in this tutorial.
The Fourth Reason: Tapestry has in it just everything one would expect from an advanced contemporary framework. A superb, easy to use user input validation, internationalization, incomparable error reporting, version 4.1 has its own AJAX components, version 5 goes even further in terms of efficiency and beauty of design... What else do you want?
So, if Tapestry is really so good, why it is not as popular as it deserves to be? This is actually a surprise for me. After spending so much effort to convince my manager that Tapestry is the right tool for our next project I feel like there is some kind of psychological barrier surrounding Tapestry. My opinion is that there is a set of prejudices that hinders Tapestry's advancement. Two of them are listed in the next section.