Project Tiles has retired. For details please refer to its Attic page.
Apache - Tiles Autotags - Building a tag library for Freemarker, JSP or Velocity Fork me on GitHub

Building a tag library for Freemarker, JSP or Velocity

Once you have created a generic tag library, Autotag will automatically generate the corresponding library for Freemarker, JSP, or Velocity. You just create a maven project and include in pom.xml:

  • The appropriate implementation of tiles-request as a dependency. For instance to build a JSP taglib:
    <dependency>
      <groupId>org.apache.tiles</groupId>
      <artifactId>tiles-request-jsp</artifactId>
      <version>1.0</version>
    </dependency>
  • Your generic tag library as a dependency. For instance:
    <dependency>
      <groupId>org.example</groupId>
      <artifactId>my-taglib</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  • The appropriate configuration of maven-autotag-plugin. For instance:
    <plugin>
      <groupId>org.apache.tiles.autotag.plugin</groupId>
      <artifactId>maven-autotag-plugin</artifactId>
      <version>1.0</version>
      <executions>
        <execution>
          <goals>
            <goal>generate-jsp</goal>
          </goals>
          <configuration>
            <packageName>org.example.mytaglib.jsp</packageName>
            <jspRuntime>org.apache.tiles.request.jsp.autotag.JspAutotagRuntime</jspRuntime>
            <taglibURI>http://example.org/mytaglib</taglibURI>
          </configuration> 
        </execution>
      </executions>
    </plugin>

    No further code is required.

Plugin goals

one or several of the following goals may be used:

generate-jsp
generates the files required for a JSP tag library. It can then be included in a JSP using the configured taglibURI.
generate-freemarker
generates the files required for freemarker user-defined directives. The directives can then be made available to freemarker by adding an instance of the generated class ...FMModelRepository to the freemarker template model.
generate-velocity
generates the files required for velocity user directives. The directives can be made available to Velocity by setting the userdirective property, either manually or by using the generated file META-INF/velocity.properties.

Plugin configuration

packageName
the destination package for the generated classes.
freemarkerRuntime
the runtime implementation of TilesRequest to use for freemarker, for instance org.apache.tiles.request.freemarker.autotag.FreemarkerAutotagRuntime.
jspRuntime
the runtime implementation of TilesRequest to use for JSP, for instance org.apache.tiles.request.jsp.autotag.JSPAutotagRuntime.
velocityRuntime
the runtime implementation of TilesRequest to use for velocity, for instance org.apache.tiles.request.velocity.autotag.VelocityAutotagRuntime.
taglibURI
the URI to use for the JSP taglib.