Project Tiles has retired. For details please refer to its Attic page.
Apache Tiles - Framework - Attribute rendering Fork me on GitHub

Attribute rendering

Attribute rendering behaviour can be customized. The "type" of an attribute can be still string, definition or template but you can define new types or use a class name directly.

Default behaviour

The default behaviour of Tiles is compatible with Tiles 2.0 and it applies both to XML definition files and JSP tags. Tiles follows these steps:

  • If the type is not specified:
  • if the value is a valid definition name, the definition is rendered;
  • if the value starts with a '/', a template will be rendered;
  • otherwise, a string will be rendered.
  • If the type is specified:
  • if the type is string, definition or template, it will be rendered like in Tiles 2.0;
  • otherwise, Tiles tries to instantiate (only once) a class whose name is specified in the "type" of the attribute. If an error occurs, it pops up as a runtime exception.

Customize attribute rendering

With Tiles 2.1+ you can customize rendering in three ways:

  • specifying new renderers;
  • overriding the default renderer for untyped attributes;
  • specifying a new renderer factory.

Custom attribute renderers

If you don't want to use class names as attribute types, you can use new "named" custom attribute renderers. You can do it by overriding the registerAttributeRenderers of BasicTilesContainerFactory if you are using Java-based configuration.

Custom default attribute renderer

The behaviour of Tiles when the type of an attribute is not specified can also be customized. You can do it by overriding the createDefaultAttributeRenderer of BasicTilesContainerFactory if you are using Java-based configuration.

Custom attribute renderer factory

The attribute renderer factory can be completely customized, leaving to you the maximum freedom of choice in the attribute renderer creation. You can specify the factory's implementation by overriding the createRendererFactory of BasicTilesContainerFactory if you are using Java-based configuration.