Integrating VRaptor with Tiles 3

by Otávio Garcia

Apache Tiles is a framework that implements the Composite View pattern, and makes possible to create templates for your application in easy way. You can found more information visiting Tiles website.

The first step is include the Tiles dependency in your Maven project as described below. If you don’t uses Maven, you can download all files and its dependencies in Tiles website.

    <version>3.0.0</version> <!-- or the latest version -->

And the next step is to add the listener that tells to Tiles when your application is up and ready.


And for the last step, you need to declare the Servlet that will respond Tiles requests. In the example below, any request to the URL *.tiles will be forwarded to Tiles templates.


And now we have Tiles listening requests.

By default, VRaptor does forwards to JSPs. So we need to override this behavior to forward to Tiles templates. We can do it changing the class DefaultPathResolver as described below.

public class TilesPathResolver extends DefaultPathResolver {

    protected TilesPathResolver(FormatResolver resolver) {

    protected String getPrefix() {
        return "/";

    protected String getExtension() {
        return "tiles";

With this code, whether the request was initiated for method CustomerController.form, VRaptor will forward to template customer.form. So we only need by now to create the template definition in the file /WEB-INF/tiles.xml:

<definition name="customer/form" template="/WEB-INF/jsp/layouts/basic.jsp">

Tiles has a older Javassist version as dependency, which might cause issues with the one used by VRaptor. To resolve this situation, what should be done is exclude the dependency as it is defined in the example below:

    <version>3.0.0</version> <!-- ou a última versão -->