Book Image

Tapestry 5: Building Web Applications

Book Image

Tapestry 5: Building Web Applications

Overview of this book

Table of Contents (17 chapters)
Tapestry 5
Credits
About the Author
About the Reviewers
Preface
Foreword
Where to Go Next

Why is Tapestry Special?


Tapestry is an example of a framework that was created keeping the developer in mind.

First of all, its paradigm is very close to that of the RAD environment. A button on the Tapestry page has an event handler method associated with it in a declarative way, and the method is invoked when the button is pressed. The Tapestry web developer doesn't need to remember that the button on the page in a user's web browser and the code of the event handler method on the web server can be thousands miles apart, and doesn't need to care about which communication protocol is being used.

This natural approach makes Tapestry significantly easier to learn than any other web development framework, and it makes the process of development much more efficient. However, there are a number of other attractive features, the combination of which makes Tapestry unique.

Tapestry HTML Templates are Free from Obtrusive Instrumentation

Every web application has to deal with HTML in one or another way. No matter what language is used on the server or what intricate logic is employed to produce the page, what actually gets sent to the user's browser is an HTML page. To make that page dynamic, web applications use some kind of HTML template, or specially prepared chunks of HTML markup, and employ some programming logic to fill that template with dynamically generated data, or manipulate HTML in a desired way.

To make this possible, virtually all web frameworks create a tight mixture of HTML markup and some other kind of code, whether it is Java, PHP, VBScript, JSP tags, JSF, ASP.NET components, or something else. Such an approach has a number of significant disadvantages.

First of all, the more complicated the page design and programming logic, the more difficult it is to weave them together. Second, this tight conglomeration of different kinds of code is extremely difficult to maintain and update. Debugging the programming logic of such a page can be quite a challenge.

Contemporary technologies like Sun's JavaServer Faces or Microsoft's ASP.NET rely on specialized development environments to handle the complexities of mixing a dynamic logic with HTML markup, but design capabilities of such specialized environments are unavoidably limited. As a result, the page design remains quite simplistic and less impressive. Code that is automatically generated by these development environments is usually far from being perfect as it has much duplication and is hard to maintain.

For many applications, it often makes sense to have a special team of designers or to use the services of an external team in order to have a professional looking interface. Unfortunately, in most web technologies the conversion of a thoroughly designed page into an HTML template is a one way procedure. The result becomes incomprehensible for any designer not familiar with programming techniques. So when it comes to a significant change in page design, it might be easier to discard the existing page and start from scratch.

Tapestry solves all these problems in the most elegant way. In Tapestry 3 and 4, templates are valid HTML documents that can be easily read and edited by any designer using a common designer's software, without breaking the logic of the page. In Tapestry 5, templates are XML documents, but they are very close to HTML. With minor reservations, all the advantages of the previous versions apply to them too. The main point is that all versions of Tapestry provide the highest possible level of separation between HTML markup and programming logic.

Custom Components are Very Easy to Create

The use of components allows you to significantly increase the productivity of web development—this is why all the new frameworks, including Tapestry, JavaServer Faces, and ASP.NET are component-based.

However, the choice of core components that come with the framework is always limited, and it is important to give developers an opportunity to create their own custom components. Naturally, such an opportunity is provided by all component-based frameworks, but the level of effort required to create a custom component differs from framework to framework quite significantly.

For instance, to create a custom JavaServer Faces component, the developer needs to know the intricate inner structure of the framework quite well, so this is a task for advanced developers only.

In Tapestry, however, creation of custom components does not require any advanced knowledge, and is perfectly possible for beginners. We will be creating non-trivial custom components in Chapter 8 of this book.

AJAX and DHTML, but No JavaScript Coding

Contemporary web applications are unthinkable without attractive and clever features powered by JavaScript and are commonly known as DHTML and AJAX. However, JavaScript has browser incompatibilities. So Tapestry comes up with a number of components that make the miracles of AJAX available to the application, but, fortunately for developers, all JavaScript is thoroughly hidden inside the framework. AJAX-enabled components are as easy to use as any other Tapestry component, so you can make your application Web 2.0-ready without ever seeing a single line of JavaScript code. Well, at least this is true for the previous version of the framework, 4.1. As of this writing, the AJAX features are currently under development (and will likely be in a finalized state by the time you read this), but it is promised that they will be even more powerful and easier to use than in Tapestry 4.1.

User Input Validation Works Like Magic

User input validation is a must for almost every web application, as users are mere mortals and will always try to submit some erroneous data. A friendly application should clearly explain to the user exactly which piece of input is wrong, but creating an input validation and error reporting subsystem can require quite a lot of work.

Tapestry 4 already had a powerful built-in infrastructure for input validation, but in Tapestry 5 it goes much further. You as a developer will have to do very little, usually simply declaring what exactly you want, while your application will not only clearly mark the erroneous fields, but also automatically display an appropriate message in the language preferred by the current user.

Built-In Internationalization Support

A Java platform itself provides substantial support for internationalization and localization but, in Tapestry we do not need to know the details of that support. We just use a few simple hooks provided by the framework to have our application displayed in as many different languages as we wish.

It is actually quite amazing to see how one mouse click totally changes the language of the application. Everything—text, images, different controls, suddenly begin to speak in a foreign language! It is an impressive feature, considering how little we have to do to enable this flexibility.

Inversion of Control Made Easy

Inversion of Control (IoC) and Dependency Injection are amongst the most popular software development paradigms these days, and they deserve their popularity. In simple terms, Inversion of Control allows developers to save effort and time by allowing some other software to take care of different routine things and provide them services whenever needed.

However, to use the benefits of Inversion of Control in an application, one might need to learn and use an additional framework like Spring. Not in Tapestry though.

Tapestry has an Inversion of Control subsystem of its own, and quite a good one. As a result, Tapestry applications contain very little Java code. All you need to write is business logic while all the infrastructure issues are handled automatically. Aditionally, the Tapestry 5 IoC container additionally provides an opportunity to implement and enforce some of the best design patterns, again, with absolute minimum code serving this purpose.

Spring framework is very popular, and working on a large-scale enterprise application, we often need to make use of some sort of back end, implemented in Spring. Thankfully, Tapestry has a special subsystem for integration with Spring. Using this subsystem in my work, I had an impression that it is easier to use Spring beans in Tapestry than in Spring itself.

More or less the same can be said about integration with another very popular framework, Hibernate. There is a special subsystem in Tapestry responsible for this integration and it is very easy to use.

To summarize, Tapestry is a mature contemporary web development framework with all the features that would be expected from such a framework and with all the power of Java platform to support it. But additionally, Tapestry is based on a unique, developer-friendly paradigm, which makes it especially easy to learn and use.