I’m glad to announce that the long awaited Tapestry 5 book is now available as paperback on lulu.com. You can purchase a copy here. The PDF version of the book is available here.

The book covers version 5.3. Once Tapestry 5.4 is released, I’ll start updating the content to cover the new version.

Enjoy reading!


You have been waiting for the Tapestry 5 book? I just launched a pre-selling campaign on Indigo. To get a PDF copy and/or print copy of the book just contribute to a Perk of your choice.

Because the book is still in progress, I would appreciate any feedback. Please drop me a line, comment on this post or use Tapestry’s community to provide your feedback. Thank you in advance.

Enjoy reading.


The Tapestry community has been waiting for a Tapestry book for so long. I’m excited to announce that I’m very close to launch an early access to the book which I have been writing for nearly two years. The new title of the book is:

Tapestry 5 - Rapid web application development in Java

I’m also happy to share with you the awesome cover for the book, which has been created by a good friend on mine¬†Ognjen Mihajlovic.

Tapestry 5 Book CoverToday I launched the website for the book: http://www.tapestry5book.com. In the next few days the book will appear on Kickstarter. You will be able to purchase a PDF copy of the book immediately by pledging for a corresponding reward.¬†If you are interested in this Tapestry book, back my project on Kickstarter. I’ll blog about it in few days.

For more news read this blog, visit book’s website and follow me on Twitter.



Hello, Kotlin!

posted in: Kotlin

Last year JetBrains announced Kotlin – a statically-typed JVM-targeted programming language. The web-based Kotlin preview has been launched recently. Check out this demo to get the first impression.

I got curious about the Kotlin programming language and attended a talk by Andrey Breslav at Devoxx 2011. Today I’m one of the lucky guys who got the access to the private EAP. After experimenting with Kotlin I decided to write a series of articles about this language in order to share with you my experience. This article is the first one and covers a basic “Hello, world” example. Let’s dive in.

Initial Java program

First we will create a¬†Java program that we later convert into Kotlin. Here is our “Hello, world!” example in Java.

package hello;

public class HelloWorld {
    private String name;

    public HelloWorld(String name) {
        this.name = name;

    public String greet() {
        return "Hello, " + name;

    public static void main(String[] args) {
        HelloWorld helloWorld = new HelloWorld("Kotlin");


An equivalent Kotlin program

Now let’s convert this example into a Kotlin program.

package hello

class HelloWorld(var name: String){

    fun greet(): String {
        return "Hello, $name"

fun main(args: Array<String>) {
    var helloWorld = HelloWorld("Kotlin")


This tiny Kotlin program demonstrates a couple of Kotlin features. Let’s start with the constructor.

Primary constructors

In Kotlin you may declare constructors immediately in the class declaration. Note that the constructor in the example above initializes class properties without having a body. Such constructors are called primary constructors.


Do properties in Kotlin have the same meaning as in Java? In contrast to Java, Kotlin classes don’t have fields that are read/written using getters and setters. Instead Kotlin classes have properties: mutable properties are declared with the var (for variable) keyword and read-only properties are declared with the val (for value) keyword. In the example above the HelloWorld class has a mutable property named name. Note that the property is declared directly in the constructor. Because the property has been declared with var keyword, we can alter its value, as shown in the following example.

var helloWorld = HelloWorld("Kotlin")
helloWorld.name = "Kotlin again"

The value of the property may be changed by assigning it directly to the property. If we would have declared the property using then val keyword, assigning a new value would result in a compiler error. Also please note that there’s no new keyword in Kotlin.


Kotlin classes have functions that are declared with the fun keyword. A function may have parameters and may have a return type. The return type Unit is what void is in Java. If a function is not a “Single-expression functions” (to be covered in a later article) and returns Unit, then the return type may be omitted.

The greet() function in the example above returns a String value. Note that the returned String contains a template expression that allows you to avoid ugly String concatenation using + operator. A template expression starts with a dollar sign ($). The value after $ represents a named placeholder that is evaluated at runtime. In this example the expression refers to the name property.


Did you notice the question mark (?) in the System.out?.println statement? Kotlin distinguishes between nullable and non-nullable references. The ?. operator is called a safe call. It’s Kotlin’s way to avoid NullPointerException. If the expression on the left hand side refers to null, the expression on the right hand side is not executed. More on Null-Safety in some of the next articles about Kotlin.

And last but not least, did you notice that we didn’t use any semicolons?

IDE support

Does Kotlin have IDE support? Well, JetBrains is the company behind IDEA which is the best IDE for Java. But also Groovy and Scala support in IDEA is excellent. It’s natural that JetBrains provides IDE support for its own language. I played around with the Kotlin plugin for IDEA. It needs some final polishing but it is already quite usable. Here is a screenshot.

That’s it for now. In this article we cover a few basic Kotlin features. I hope you enjoyed it. Stay tuned.


Tapestry 5.3 release candidate is out and the final release is approaching. That’s why I want to share with you a new cool feature which will make your life easier.

As a Tapestry user you surely know Tapestry’s component reference documentation. This documentation is generated using Tapestry’s Maven plugin. Many of Tapestry users, who are also Maven users, are using this plugin for their custom components. Unfortunately there was no solution for non-Maven users before Tapestry 5.3.

Starting with version 5.3 Tapestry provides a JavaDoc plugin which can be used to generate a component reference documentation as part of JavaDoc. An example is demonstrated in the following screenshot.


Check out this JavaDoc to see what is possible with the new JavaDoc plugin.

What is needed to integrate a component reference into the JavaDoc? You just need to place¬†@tapestrydoc on the component’s classes, as shown in the following example.

 *  Here comes your JavaDoc...
 * @tapestrydoc
public class MyComponent {

Additionally you need to use Tapestry’s taglet when generating the JavaDoc. For more details on JavaDoc Taglets see here.

Integration with Maven

Now let’s see how to tell Maven’s JavaDoc plugin to use Tapestry’s taglet.


That’s all. Tapestry’s JavaDoc plugin will do the rest and generate kickass JavaDocs.

Integration with Gradle

If you are interested how to generate the component reference with Gradle, please check out Tapestry’s build script.

Integration with Ant

Honestly I have no idea how to do that as I didn’t use Ant for years. I’m pretty sure it is possible. Please read the¬†documentation for Ant’s JavaDoc plugin for more details.

Stay tuned!


As already announced here, I’ll be publishing my Tapestry 5 book on my own. Because “Tapestry 5 in Action” sounds like a book published by Manning, I decided to choose another title.

Coming up with a cool title is a challenge. That’s why I decided to ask the community for a new title for the book. If you have a proposal, please drop me a line or comment on this post. Please post any idea you have (with or without subtitle), no matter how crazy it is. The author of the chosen title will be rewarded by a free PDF copy when the book is published.

Looking forward to see your ideas.


Some weeks ago I have been informed by Manning Publications that the Tapestry 5 in Action book is canceled. Based on MEAP sales Manning did a sales forecast. It looks like the book is financially not attractive enough.

As you can imagine, this news made me upset. I was working on the book for about 8 month now. The half of the book (almost 250 pages) is already finished and I was looking forward to see the book in a final shape. After the MEAP has been started, I’ve got a lot of positive feedback regarding the book. It looks like the readers like the book’s content very much.

Manning’s decision was more than a surprise for me. After being upset for a couple of days I changed my opinion about Manning’s decision. Now I believe that this cancelation is the best thing that could happen to the book. I decided to publish the book on my own (probably on lulu.com). First of all, it is much more financially attractive for me. Secondly, I’ll be able to publish as many editions as I wish. I can update the book’s content every time a new Tapestry version is released. The only disadvantage is that lulu.com doesn’t provide something like an “early access program” so that the readers will need to wait until the book is finished.

If you was one of the MEAP customers who bought the Tapestry 5 in Action book, there is no reason to be sad. The book is going to be published. I promise you.

Stay tuned!


Frequently web applications have a requirement¬†to execute some¬†business¬†logic which is not bound to any HTTP request. For example, you might want to execute some periodic maintenance job to cleanup the database or a job sending messages to your users. In this article I’ll show you how to register jobs to be executed by Tapestry without blocking any incoming HTTP request.

Interval Jobs

Imagine you have a CleanupService service to be executed for database cleanup. The service’s interface is shown in the following example. The service implementation details are not interesting for this article as they are very specific to your application.

public interface CleanupService {
    void clean();

Now let’s schedule a periodic execution of the cleanup at application’s startup. This is accomplished by contributing to the RegistryStartup service’s configuration, as shown in the following example.

public class AppModule {

    public static void scheduleJobs(
                   PeriodicExecutor executor,
                   final CleanupService cleanupService) {

            new IntervalSchedule(300000L),
            "Cleanup Job",
            new Runnable() {
                public void run() {

As of Tapestry 5.3 the PeriodicExecutor service can be used to schedule jobs. In the example above, this service is injected into a startup method. The service’s addJob method is used to register jobs to be executed.This method takes three parameters:

  1. Instance of Schedule: defines when to execute the next job
  2. Name used in debugging output related to the job
  3. Instance of Runnable that represents the work to be done

In the example above, a IntervalSchedule instance is used to schedule a job to be executed every 300000 milliseconds (5 minutes). Note that the Runnable is just a wrapper around the CleanupService.

Using CRON expressions

Instead of defining intervals for job executions, Tapestry also allows you to use CRON expressions, such as described here. Note that Tapestry uses the CRON parser from the Quartz Scheduler without depending on it.

The following example demonstrates how to use CRON expressions.

public class AppModule {

    public static void scheduleJobs(
                   PeriodicExecutor executor,
                   final CleanupService cleanupService) {

            new CronSchedule("0 0/5 14 * * ?"),
            "Cleanup Job",
            new Runnable() {
                public void run() {

In the example above, a job is registered to be executed every 5 minutes starting at 2pm and ending at 2:55pm, every day.

Happy scheduling.


The Tapestry team has been very busy in the last months and it looks like Tapestry 5.3 goes Beta. While we are working on fixing last minor issues before version 5.3 becomes generally available, I want to share with you some of the new upcoming features.

From the user perspective Tapestry 5.3 will be the most attractive release since 5.0. This article gives you a short overview.

New Components

Several components has been added to the core library:

  • Kaptcha / KaptchaField: Allow you to protect your forms from spam.
  • Tree: Used to render a recursive tree structure, with expandable/collapsable/selectable nodes.
  • Dynamic: An awesome component¬†allowing a component to render itself differently at different times, by making use of an external template file. More details on this component follow in the next post
  • Checklist:¬†Multiple selection component. Generates a UI consisting of a list of check¬†boxes. This component is used as alternative to the Palette component.
  • Alerts: Used to display alerts.


In the past the only way to present some messages to the user was to persist some page properties using the flash strategy.¬†Now Tapestry provides a central mechanism for handling user alerts: the AlertManager service and the Alerts component. Using AlertManager service you can add alerts which are presented to the user using the Alerts component. Alerts can be added during both traditional and Ajax requests, and may be transient (displayed for a few seconds), normal, or sticky (persist until the user expressly dismisses them). Alerts support three severities: info, warn(ing) and error; the look and feel can be customized by overriding Tapestry’s default CSS rules.

Template Skinning

I discussed template skinning feature in this article.

Improved Exception Reporting

Tapestry is known to provide excellent messages when something goes wrong. In version 5.3, the exception reporting has been improved for Ajax requests. Please watch this screencast for more details.

New JavaScript Abstraction Layer

As you probably know, Tapestry is stuck with using¬†Prototype and Scriptaculous for backward compatibility reasons. A lot of Tapestry users has been complaining about missing support of jQuery. Those of you, how can’t live without jQuery are probably using this Tapestry/jQuery library which allows you to get rid of Prototype and Scriptaculous.

Breaking backward compatibility with existing apps just by rewriting the client-side code to jQuery is not an option. Also¬†tying Tapestry to jQuery wouldn’t be a good decision. If yet another JavaScript library will become successful next year and everybody starts to migrate, you are stuck again. A much better solution is to provide an abstraction layer which allows you to use any JavaScript library you like just by replacing a couple of files. Some work has already been done in Tapestry 5.3. The transition is done¬†gradually and will be finalized in version 5.4.

Improved Ajax

The MultiZoneUpdate class has been deprecated in favor of AjaxResponseRenderer service. This service manages the rendering of a partial page render as part of an Ajax response. Let’s see a simple example.

public class AjaxDemo {
    private Block block;

    private AjaxResponseRenderer ajaxResponseRenderer;

    private Asset library;

    void onActionFromUpdate() {
        ajaxResponseRenderer.addRender("zone", block);

                    new JavaScriptCallback() {
            public void run(JavaScriptSupport support) {

                     new JSONObject("id", "message",
                                    "message", "Updated"));

As you can see, the new API allows us to update a zone with the content from a renderer (such as a Block, Component or other object that can be coerced to RenderCommand). It is also possible to queue a JavaScriptCallback to be executed during the partial markup render. In this example the callback is used to import a JavaScript library as part of the rendered page and to add a call to a client-side function inside the Tapestry.Initializer namespace.

JSR 330 Integration

Starting from Tapestry 5.3, it’s possible to use JSR-330 annotations for injection. Using the standard annotations, your code in the service layer doesn’t need to depend on Tapestry. Please read this article for more details.

JPA 2 Integration

Finally, Tapestry provides a native JPA 2 integration. How does it differ from¬†Tynamo’s JPA integration? First of all, it is maintained by the Tapestry team, that will ensure the backward compatibility with future releases. Secondly, it provides some features that were not available in Tynamo. For example, you can have multiple persistence units in the same application. Furthermore, Tapestry allows you to configure JPA without XML. Read this article for more details.

JavaScript and CSS Compression

A module integrating Yahoo’s¬†YUI Compressor has been added. This library allows you to compress your JavaScript and CSS.

Component Reference

Great news for component developers. Starting with Tapestry 5.3 generating a component reference will be as easy as writing JavaDoc. You no longer need to use Maven. Instead you just need to place @tapestrydoc in the component’s class JavaDoc. That’s all. The following screenshot¬†demonstrates the result.

Scheduling Jobs

The PeriodicExecutor service has been introduced to allow execution of scheduled jobs. The following example demonstrates how to schedule a job to be executed every 5 minutes.

public class PeriodicExecutorDemo {

    public PeriodicExecutorDemo(PeriodicExecutor executor) {

          new IntervalSchedule(300000L),
           new Runnable () { void run() { ... }; } );



Plastic is a bytecode transformation library based on ASM. Plastic is designed to simplify the run-time transformation of Java classes. The most parts of the internal API using Javassist has been rewritten to use Plastic. The Javassist-based API has been deprecated and will be removed in Tapestry 5.4. Starting from version 5.4 Tapestry will not longer depend on Javassist. Yay!


Have fun with Tapestry and stay tuned!


In this article I want to share with you a new awesome Tapestry feature introduced in 5.3. This feature allows you to provide different skins for a single page by creating several templates. These different templates are used by Tapestry to render the same page in a special way for different clients. For example, when developing a web application for both standard and mobile clients you might need to render the same page different depending on the current client. So, you need to create two different templates for each page and choose one of them depending on the user agent sent by the client.

In the Extending Template Lookup Mechanism article I described how to accomplish that in Tapestry 5.2. The described approach was not ideal because of the issue with Tapestry’s template cache. ¬†Anyway, the new API in Tapestry 5.3 is cool. Let’s see it in action. First, let me show you how the template cache works.

Template cache

As you probably know the structure of Tapestry’s pages is static. I don’t want to cover the reasons for the static structure in this article; please read Tapestry’s documentation for more details. Because of the static structure the instances of Tapestry pages can be cached. You can imagine the page cache as a multidimensional coordinate system. By default the cache is two-dimensional; one of the axes is for page classes, the other for locales. If you have n pages in your application and you configured Tapestry to support m locales, then there might be maximal n * m page instances in the cache, as illustrated in the following figure.

The new API in Tapestry 5.3 allows you to add additional dimensions to the cache matrix. For example, a new dimension might be the client. Let’s say we have two different clients: standard and mobile. In this case the maximal number of page instances is n * m * 2, as shown in the following example.

Now let’s explore how to provide client-specific templates for pages and how to add additional dimensions to the page cache.

Locating component resources

The ComponentResourceLocator interface is the central service for locating resources for components. The interface defines two methods:

  • locateTemplate: Locates the template for a component (including pages and base classes).
  • locateMessageCatalog: Locates the message catalog for a component.

Both methods take a ComponentResourceSelector parameter. Briefly speaking, ComponentResourceSelector defines the axes to be used by the page cache.

The default implementation of the ComponentResourceLocator interface reads only the Locale from the passed ¬†ComponentResourceSelector instance, so that the cache is 2-dimensional. Let’s create our own implementation of ComponentResourceSelector interface which will make use of a third dimension. The following example demonstrates how to accomplish that.

public class CustomComponentResourceLocator
              implements ComponentResourceLocator {

    private final ComponentResourceLocator delegate;

    private final Resource contextRoot;

    private final ComponentClassResolver resolver;

    public CustomComponentResourceLocator(
          ComponentResourceLocator delegate,
          Resource contextRoot,
          ComponentClassResolver resolver) {

        this.delegate = delegate;
        this.contextRoot = contextRoot;
        this.resolver = resolver;

    public Resource locateTemplate(
              ComponentModel model,
              ComponentResourceSelector selector) {

        if(!model.isPage()) {
            return null;

        String className = model.getComponentClassName();

        String logicalName =

        Client client = selector.getAxis(Client.class);

        if (client == Client.MOBILE) {
            String path = String.format("mobile/%s.%s",

            Resource resource = contextRoot.forFile(path);

            if (resource.exists()) {
                return resource.forLocale(selector.locale);

        return delegate.locateTemplate(model, selector);

    public List<Resource> locateMessageCatalog(
              Resource baseResource,
              ComponentResourceSelector selector) {

        return delegate.locateMessageCatalog(
                               baseResource, selector);

As you can see, our implementation is a decorator for the original ComponentResourceLocator implementation. Inside the locateTemplate() method the passed ComponentResourceSelector instance is used to retrieve the third axis which is of type Client. If the current client is Client.MOBILE, we try to locate a special template from the mobile sub-folder. If a page template exists in this sub-folder, it is returned. Otherwise we delegate to the original ComponentResourceLocator implementation in order to return the default template.

Next, we need to decorate the built-in ComponentResourceLocator by providing a decorate method in the AppModule class.

public class AppModule {

   @Decorate(serviceInterface = ComponentResourceLocator.class)
   public static Object customComponentResourceLocator(
           ComponentResourceLocator delegate,
           @ContextProvider AssetFactory assetFactory,
           ComponentClassResolver componentClassResolver) {

        return new CustomComponentResourceLocator(

Where does the Client axes come from? This is where the ComponentRequestSelectorAnalyzer service comes into play. This service has been introduced in Tapestry 5.3 and is responsible for determining the ComponentResourceSelector for the current request. The default implementation of the interface creates a 2-dimensional¬†ComponentResourceSelector instance; the axes are page class and Locale for the current request. Let’s implement our own ComponentRequestSelectorAnalyzer implementation which will return a 3-dimensional ComponentResourceSelector. The following example demonstrates how to accomplish that.

public class CustomComponentRequestSelectorAnalyzer
                implements ComponentRequestSelectorAnalyzer {

    private final ThreadLocale threadLocale;

    private ClientService clientService;

    public CustomComponentRequestSelectorAnalyzer(
          ThreadLocale threadLocale,
          ClientService clientService) {

        this.threadLocale = threadLocale;
        this.clientService = clientService;

    public ComponentResourceSelector buildSelectorForRequest() {

       Locale locale = threadLocale.getLocale();
       Client client = clientService.getCurrentClient();

        return new ComponentResourceSelector(locale)
                      .withAxis(Client.class, client);

As you can see, we create a ComponentResourceSelector by passing the current Locale to the constructor. Then we add an additional axis of type Client. The current Client is retrieved from ClientService which is your custom service. Probably you would implement such a service by examining the User-Agent HTTP header. Anyway, the implementation details of ClientService are not interesting for this article.

Finally, we need to override the original implementation of ComponentRequestSelectorAnalyzer service by contributing to the ServiceOverride service’s configuration, as shown in the following example.

public class AppModule {

    public static void bind(ServiceBinder binder) {


    public static void overrideSelectorAnalyzer(
           MappedConfiguration<Class, Object> cfg,

          ComponentRequestSelectorAnalyzer analyzer){

           cfg.add(ComponentRequestSelectorAnalyzer.class, analyzer);

That’s all. Whenever you ClientService determines that the current client is a mobile devices and returns Client.MOBILE, Tapestry will look for a template in the mobile sub-folder in the context root. If found it is used to render the response for the mobile device. If not found, the default template is used.

Have fun with Tapestry and stay tuned.

Tapestry 5 Blog - Copyright © 2009 - Eclectic Theme by Your Inspiration Web - Powered by WordPress