In , a page or a component development usally involves three elements : a template file, a specification file and Java class. It is the most common case (even if there are some cases where one or two of theses elements are not used).

What I find annoying in the Tapestry specification files is :

  • Inheritance : pages or components class can inherit but not their specifications. It leads to duplication of informations.
  • Composition : pages or components class can be composed but not specifications. It leads to duplication of informations.
In short, it really bugs me not to be able to apply Java concepts to both class and specification files.

As I am exploring the and its annotations, I wonder if 4.0 could handle components and pages definitions without specification files (the .page or .jwc files), only by using Java annotations. The basic idea behing is to move the content of the specification file into Java class by using annotations. Let's take an example :

The following specification part :

<component id="select" type="DirectLink">
    <binding name="listener" value="listener:makeGuess"/>
    <binding name="parameters" value="letterForGuessIndex"/>
    <binding name="disabled" value="letterGuessed"/>
will become the following annotations :
@Component(type = "DirectLink", bindings = { "listener=listener:makeGuess", "parameters=letterForGuessIndex", "disabled=letterGuessed" })
public abstract DirectLink getSelect();
and so on. At the end, all the content of the specification file will be translated into annotations.

To go further and to illustrate the general concept on a sample application, I took application and convert all the pages and components using the method described above. It is available for download (please note that a JDK 5.0 is required to run this application), source code is included (under public domain of course). In short, I am using an ISpecificationDelegate implementation that can handles specification-less pages and components.

As a conclusion, I will said that without specification files, the development under Tapestry can benefit from :

  • True inheritance. Annotations are inherited by sub-classes so pages or components are clearer and simpler.
  • True composition. As most annotations are put on abstract methods, they can be gathered in interfaces. Creating a page can be as simple as compositing interfaces on top of abstract class.
  • Less error-prone. The specification file can be a source of error as it must be in sync with the template and the class.

This development method as also its drawbacks :

  • Class have more lines and mostly reference components through abstract getters. This can be addressed by factorisation and use of inheritance and composition.
  • Annotation syntax is hardier to read than its XML counterpart.
  • JDK 5.0 is required to support this feature.

I am requesting feedback from the community about this approach. Is it a way to reduce the development cycle in the KISS philosophy or is it just a overuse of the Java annotations ?