This project has retired. For details please refer to its Attic page.
Apache Tiles - Framework - Using multiple containers

WARNING!!! Configuration with initialization parameters is deprecated! If you still want to use it, please refer to 2.1 version of this page.

Defining multiple containers

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


To use an alternate container, you need to override the getContainerKey method of AbstractTilesInitializer this way:

public class TestAlternateTilesListener extends AbstractTilesListener {

    /** {@inheritDoc} */
    protected TilesInitializer createTilesInitializer() {
        return new TestAlternateTilesInitializer();

     * Test Tiles initializer for Tiles initialization of the alternate container.
    private static class TestAlternateTilesInitializer extends AbstractTilesInitializer {

        // Other customizations go here.

        /** {@inheritDoc} */
        protected String getContainerKey(
                TilesApplicationContext applicationContext) {
            return "myContainerKey";

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.