5

I am using Apache tiles for templating and part of the template is a header text. This text depends on the section the page belongs to. Each page contains a bean and the header text is built using the properties of that bean. The bean will have a different name for each page. So, in my JSP file I would have something like this:

<div>${myBean.id} - ${myBean.name}</div>

I want to get that expression in the tile definition and I tried this:

<definition template="/WEB-INF/tiles/layout/mytemplate.jsp">
  <put-attribute name="title" expression="${myBean.id} - ${myBean.name}" />
</definition>

And in the template I do:

<div class="title-header"><tiles:insertAttribute name="title" /></div>

But the result is the unprocessed EL expression:

<div>${myBean.id} - ${myBean.name}</div>

The code has been simplified here to keep this post concise but this is exactly what I'm trying to do. There are also reasons why I am trying to do it this way.

Any idea why the EL expresion is not being processed?

Thanks

NOTE: I am fairly new to JSP and Apache Tiles so I may not have used the correct terminology.

Benoit Martin
  • 3,323
  • 2
  • 22
  • 22
  • Am I asking a stupid question or is there just nobody that can help me? – Benoit Martin Aug 22 '11 at 23:51
  • 2
    Its looks fine, can you post your tiles configuration please? Have you tried evaluating the ${myBean.id} directly in the JSP to check its actually there? Have a look here: http://tiles.apache.org/2.1/framework/tutorial/advanced/el-support.html, do you have tiles-el.jar on your classpath? To enable EL support you need to set the org.apache.tiles.evaluator.AttributeEvaluator parameter, – Barry Pitman Oct 27 '11 at 07:34

1 Answers1

6

I just wanted to point out that Barry's answer (in his comment on the original post) helped me out. You need to have tiles-el.jar on your classpath (if you want to use the standard EL; presumably you need the corresponding JARs for MVEL or OGNL).

Tiles 2. Regarding AttributeEvaluator, here's how you can set that up if you're using Spring:

<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles/**/views.xml</value>
        </list>
    </property>

    <!-- Initialize expression language support for use in Tiles definitions. -->
    <property name="tilesProperties">
        <props>
            <prop key="org.apache.tiles.evaluator.AttributeEvaluator">org.apache.tiles.evaluator.el.ELAttributeEvaluator</prop>
        </props>
    </property>        
</bean>

Tiles 3. Spring's TilesConfigurer for Tiles 3 automatically checks the classpath for the JSP API 2.1 and Tiles EL JARs. If it finds them both, it automatically creates an EL-aware attribute evaluator.