tiles-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kai <...@ich-geh-kaputt.de>
Subject EL-Expression in definition ignores page-scope
Date Sat, 08 Oct 2011 19:39:50 GMT
Hello!

I am trying to decorate one base-template mit varying 
extra-functionality. For example one listing of objects, with different 
additional informations, depending on the access rights granted to the user.

My idea was, to use a nested anonymous definition, which pics up a 
page-context variable via an EL-expression. Here is a simplified 
version, of what I have put together:

The definition:
--------------------
   <definition name="list" template="/WEB-INF/templates/list.jsp">
     <put-attribute name="dynamic">
       <definition template="/WEB-INF/templates/dynamic.jsp">
         <put-attribute name="var" expression="${i}"/>
       </definition>
     </put-attribute>
   </definition>
---------------------

list.jsp:
---------------------
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" 
session="false" %>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="t" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
   <head><title>test</title></head>
   <body>
     <ul>
       <c:forEach var="i" begin="1" end="10" step="1">
         <li><em>Loop #${i}:</em><t:insertAttribute name="dynamic"/></li>
       </c:forEach>
     </ul>
   </body>
</html>
---------------------

dynamic.jsp:
---------------------
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" 
session="false" %>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="t" %>
<t:importAttribute name="var" toName="x" ignore="true"/>
Dynamic variable in nested definition: <strong>${x}</strong>
---------------------

The problem ist:
The EL-expression ${i} does not pick up the variable from the page-scope!


If I push the variable to request-scope with an <c:set var="i" 
value="${i}" scope="request"/> inside the <c:forEach>-loop, everything 
works fine. But that would polute the "global namespace" and might 
therefore lead to other hard to find errors later on. Besides, using the 
EL-expression would be pretty pointless than, because the variable is 
visible in the nested definition anyway.


Am I missing something, is this a bug, or why is it not possible to pick 
up variables from page-scope via EL-expressions in definitions?


Greetings Kai

Mime
View raw message