~~ $Id$ ~~ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ ----------- Expression Language (EL) support ----------- Expression Language (EL) support With Tiles it is possible to use EL not only in JSP pages, but also in XML definition files. * Configuration To enable EL support in XML definition files, you have to configure the class of the {{{../../apidocs/org/apache/tiles/evaluator/AttributeEvaluator.html} AttributeEvaluator}}. If you are using declarative configuration in <<>> file, you have to use the {{{../../config-reference.html#org.apache.tiles.evaluator.AttributeEvaluator} org.apache.tiles.evaluator.AttributeEvaluator}} parameter. In the case of <<>>: ------------------------------------ tiles-init org.apache.tiles.web.startup.TilesServlet org.apache.tiles.evaluator.AttributeEvaluator org.apache.tiles.evaluator.el.ELAttributeEvaluatr ------------------------------------ If you are using programmatic configuration via Java, override the {{{../../apidocs/org/apache/tiles/factory/BasicTilesContainerFactory.html#createEvaluator(java.lang.Object,%20org.apache.tiles.TilesApplicationContext,%20org.apache.tiles.context.TilesRequestContextFactory,%20org.apache.tiles.locale.LocaleResolver)} createEvaluator}} method, providing <> of the instance of the <<>>. If you are using Servlet 2.5 or above, you can leverage your container EL support. ------------------------------------ /** {@inheritDoc} */ @Override protected AttributeEvaluator createEvaluator(Object context, TilesApplicationContext applicationContext, TilesRequestContextFactory contextFactory, LocaleResolver resolver) { ELAttributeEvaluator evaluator = new ELAttributeEvaluator(); evaluator.setApplicationContext(applicationContext); MultiversionExpressionFactoryFactory efFactory = new JspExpressionFactoryFactory(); efFactory.setApplicationContext(applicationContext); evaluator.setExpressionFactory(efFactory.getExpressionFactory()); 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()); } }; evaluator.setResolver(elResolver); return evaluator; } ------------------------------------ If you are using Servlet 2.4, you still can use Tiles EL support but: * You have to put <<>> (or newer version) in your classpath. * Use <<>> instead of <<>>. * Usage Let's use this example: ------------------------------------ ------------------------------------ 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.