Expression Language (EL) support

With Tiles it is possible to use EL not only in JSP pages, but also in XML definition files.


To enable EL support in XML definition files, you have to configure the class of the AttributeEvaluator.

If you are using declarative configuration in web.xml file, you have to use the org.apache.tiles.evaluator.AttributeEvaluator parameter. In the case of TilesServlet:


If you are using programmatic configuration via Java, override the createEvaluator method, providing only the creation of the instance of the AttributeEvaluator.

If you are using Servlet 2.5 or above, you can leverage your container EL support.

    /** {@inheritDoc} */
    protected AttributeEvaluator createEvaluator(Object context,
            TilesApplicationContext applicationContext,
            TilesRequestContextFactory contextFactory, LocaleResolver resolver) {
        ELAttributeEvaluator evaluator = new ELAttributeEvaluator();
        MultiversionExpressionFactoryFactory efFactory = new JspExpressionFactoryFactory();
        ELResolver elResolver = new CompositeELResolver() {
                add(new TilesContextELResolver());
                add(new TilesContextBeanELResolver());
                add(new ArrayELResolver(false));
                add(new ListELResolver(false));
                add(new MapELResolver(false));
                add(new ResourceBundleELResolver());

        return evaluator;

If you are using Servlet 2.4, you still can use Tiles EL support but:

  • You have to put jasper-el-6.0.16.jar (or newer version) in your classpath.
  • Use TomcatExpressionFactoryFactory instead of JspExpressionFactoryFactory.


Let's use this example:

  <definition name="test.composite.el.definition" templateExpression="${layout}"
      <put-attribute name="title"  value="This is a configured composite definition."/>
      <put-attribute name="header" value="/header.jsp"/>
      <put-attribute name="body"   expression="${requestScope.body}"/>

Before rendering the definition:

  • The template name will be taken from the "layout" attribute, searched in every scope.
  • The body will be taken from the "body" attribute in request scope.