stanlick on 09/11/08 00:29, wrote:
I would like to use EL in tiles definitions. Is it supported by Struts 2.x
and is there a recipe for this? I downloaded Tiles 2.1.0 and reviewed the
changes, but the web.xml has undergone radical change and I thought I'd do a
little fact finding before performing open heart surgery on my working
application.
Hi Scott,
not directly in tiles.xml, however with just one more step, it's easy. This is
the approach I took.
Tiles.xml definition:
<definition name="collatedAnalysisInsert.tile"
extends="collatedAnalysisList.tile">
<put-attribute name="tilesSubmitAction" value="collated-analysis/new" />
<put-attribute name="bodyContentTile"
value="/WEB-INF/jsp/collated-analysis/edit.jsp" />
<put-attribute name="tilesContextHeader"
value="collatedanalysis.insert.pageHeader" />
<put-attribute name="tilesAdditionalTitle" type="string"
value="collatedRun.portfolio.title" />
</definition>
Sorry it's a bit of dry example. The last attribute 'tilesAdditionalTitle' is
actually the reference to a javabean object with nested objects found in the
requestAttributes, but as far as tiles is concerned, it's just a string attribute.
In the JSP, I can retrieve it from the requestAttributes using the JSTL
requestScope[] map. I use it like this:
<tiles:importAttribute />
<h1 class="contextHeader">
<fmt:message key="${tilesContextHeader}">
<c:if test="${!empty tilesAdditionalTitle}">
<fmt:param value="${requestScope[tilesAdditionalTitle]}" />
</c:if>
</fmt:message>
</h1>