Defining multiple containers

With Tiles 2.1 it is possible to use more that one Tiles container in your application.

Configuration

To use an alternate container, it must be configured through the use of the org.apache.tiles.startup.BasicTilesInitializer.CONTAINER_KEY initialization parameter. For example:

<servlet>
    <servlet-name>tiles-alt</servlet-name>
    <servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
    <init-param>
        <param-name>org.apache.tiles.startup.BasicTilesInitializer.CONTAINER_KEY</param-name>
        <param-value>alternate</param-value>
    </init-param>
</servlet>

Selecting one non-default container

Once defined, it is possible to select a non-default container through Java or JSP

Selection through Java

It is possible to use, for the current request, a different container stored under another key, by using setCurrentContainer method of ServletUtil class. For example:

ServletUtil.setCurrentContainer(request, applicationContext, "myContainerKey");

If the last parameter is null, the default container is selected.

Selection through JSP

The current container can be selected also through the use of JSP:

<tiles:setCurrentContainer containerKey="myContainerKey" />

If the containerKey attribute is not present, the default container is selected.