Kontakt

Archive for the ‘Tapestry’ Category

Tapestry 5 Book Is Here

Freitag, Januar 25th, 2013

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!

Tapestry 5 Book EAP Launched

Montag, Juli 30th, 2012

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.

Progress on Tapestry 5 Book

Mittwoch, Juli 4th, 2012

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.

 

JavaDoc Plugin For Component Reference Documentation

Mittwoch, November 9th, 2011

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.

<project>
  ...
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <version>2.8</version>
        <configuration>
          ...
          <taglet>org.apache.tapestry5.javadoc.TapestryDocTaglet</taglet>
          <tagletArtifact>
             <groupId>org.apache.tapestry</groupId>                       
             <artifactId>tapestry-javadoc</artifactId>                       
             <version>5.3-rc-3</version>                   
          </tagletArtifact>
          ...
        </configuration>
      </plugin>
    </plugins>
    ...
  </reporting>
  ...
</project>

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!

Wanted: New Title For The Tapestry Book

Dienstag, Oktober 4th, 2011

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.

Publishing Tapestry 5 in Action Book On My Own

Freitag, September 23rd, 2011

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!

Scheduling Jobs With Tapestry

Sonntag, September 18th, 2011

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 {

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

        executor.addJob(
            new IntervalSchedule(300000L),
            "Cleanup Job",
            new Runnable() {
                public void run() {
                    cleanupService.clean();
                }
            });
    }
}

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 {

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

        executor.addJob(
            new CronSchedule("0 0/5 14 * * ?"),
            "Cleanup Job",
            new Runnable() {
                public void run() {
                    cleanupService.clean();
                }
            });
    }
}

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.

Tapestry 5.3 Preview

Montag, August 22nd, 2011

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.

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 {
    @Inject
    private Block block;

    @Inject
    private AjaxResponseRenderer ajaxResponseRenderer;

    @Inject
    @Path("MultiZoneUpdateDemo.js")
    private Asset library;

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

        ajaxResponseRenderer.addCallback(
                    new JavaScriptCallback() {
            public void run(JavaScriptSupport support) {

                support.importJavaScriptLibrary(library);
                support.addInitializerCall(
                     "writeMessageTo",
                     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) {

       executor.addJob(
          new IntervalSchedule(300000L),
          "MyJob",
           new Runnable () { void run() { ... }; } );
    }
}

 

Plastic

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!

Template Skinning

Freitag, Juni 24th, 2011

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;
    }

    @Override
    public Resource locateTemplate(
              ComponentModel model,
              ComponentResourceSelector selector) {

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

        String className = model.getComponentClassName();

        String logicalName =
              resolver.resolvePageClassNameToPageName(className);

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

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

            Resource resource = contextRoot.forFile(path);

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

        return delegate.locateTemplate(model, selector);
    }

    @Override
    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(
                      delegate,
                      assetFactory.getRootResource(),
                      componentClassResolver);
    }
}

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;
    }

    @Override
    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) {
        binder.bind(ClientService.class,
                    ClientServiceImpl.class);

        binder.bind(ComponentRequestSelectorAnalyzer.class,
                    CustomComponentRequestSelectorAnalyzer.class)
             .withId("CustomComponentRequestSelectorAnalyzer");
    }

     @Contribute(ServiceOverride.class)
    public static void overrideSelectorAnalyzer(
           MappedConfiguration<Class, Object> cfg,

          @InjectService("CustomComponentRequestSelectorAnalyzer")
          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.

On Tapestry’s Performance

Dienstag, Juni 14th, 2011

Tapestry claims to be performant and scalable. You want a proof? Than read this great post. The author compares the performance of Rails, Wicket, Grails, Play, Tapestry, Lift, JSP, Context. It is not a surprise that Tapestry outperformed the most of the competitors. Here are the results:

For more details on the benchmark please read the original article.

Two years ago Peter Thomas made a similar comparison and the result was not that good for Tapestry. It seems like two year ago Wicket was ahead of ¬†Tapestry and Grails. But the recent comparison shows that Wicket’s performance is the worst. What could be the reason for such different results? First of all, I believe that Peter Thomas’ comparison was not accurate. Peter is known to be a Wicket lover. When the comparison is made by an unbiased person, then the results look completely different.¬†Another possible reason could be that Tapestry improved in the last two years a lot. Removal of page pooling and other important changes might be the reason for that. However, seeing that Tapestry’s performance just rocks is a satisfaction.

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