springapachetilesapache-tilestiles2

Migrating from Tiles 2.1.4 to 2.2.2 - Property-based Configuration Removed


We have a project that is using Tiles 2.1.4 & Spring 3.2.8 and I am trying to upgrade it to Tiles 2.2.2 & Spring 4.3.1. The code used for configuring Tiles is like this:

import org.apache.tiles.TilesException;
import org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO;
import org.apache.tiles.renderer.impl.BasicRendererFactory;
import org.springframework.web.servlet.view.tiles2.TilesConfigurer;

import java.util.Properties;

public class DefaultTilesConfigurer extends TilesConfigurer {
    ....

    @Override
    public void afterPropertiesSet() throws TilesException {
        //set default properties
        Properties props = new Properties();
        props.setProperty(BasicRendererFactory.TYPE_RENDERERS_INIT_PARAM, "template,"+SkinTemplateAttributeRenderer.class.getName());
        props.setProperty(BasicRendererFactory.DEFAULT_RENDERER_INIT_PARAM, UntypedSkinAttributeRenderer.class.getName());
        props.setProperty(CachingLocaleUrlDefinitionDAO.CHECK_REFRESH_INIT_PARAMETER, Boolean.toString(refreshable));
        super.setTilesProperties(props);
        //initialize
        super.afterPropertiesSet();
    }
}

The thing is org.springframework.web.servlet.view.tiles2.TilesConfigurer#setTilesProperties is removed in Tiles 2.2. I have checked 2.1 and 2.2 configuration pages of Apache but I didn't understand how I can configure Tiles 2.2 with same parameters.

Thanks...


Solution

  • You need to strongly consider whether it makes sense to use Tiles 2.2 with Spring 4, given that it's officially deprecated in favor of Tiles 3.0. Why not upgrade to Tiles 3 while you're at it?

    That being said, TilesConfigurer#setTilesProperties() in Spring 3 is equivalent to setting init-param elements on the TilesServlet context, so you could move the configuration to your web.xml file, e.g.

    <servlet>
        <servlet-name>tiles</servlet-name>
        <servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
        <init-param>
            <param-name>
              org.apache.tiles.renderer.impl.BasicRendererFactory.DEFAULT_RENDERER_INIT_PARAM
            </param-name>
            <param-value>
              com.test.UntypedSkinAttributeRenderer
            </param-value>
        </init-param>
        ...
    </servlet>
    

    Note: the above is deprecated in Tiles 2.2.

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

    References:

    https://tiles.apache.org/2.1/framework/tutorial/configuration.html

    http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/servlet/view/tiles2/TilesConfigurer.html