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

Defining multiple containers

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 TilesAccess class. For example:

TilesAccess.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.