Am 11.10.2011 09:17, schrieb Antonio Petrelli:
2011/10/10 Kai<[email protected]>
  * using a view preparer for the definition that computes the attribute to
put as "dynamic" attribute.

  This might be the best way.
But on a quick glance at the ViewPreparer-Interface ant its two arguments
TilesRequestContext and AttributeContext, I couldn't figure out, how I
counld access the picture-instance, which lives inside the nested scope of
the forEach-Loop, from there...


Sorry but probably I said something in one of my first emails in this thread
that I thought it was obvious.
The idea is to iterate the list of items (in your case pictures) and pass
them as attributes to the underlying attribute.
Therefore, when you do:
<t:insertAttribute name="dynamic">
<t:putAttribute name="picture" value="${iteratedPicture}" />
</t:insertAttribute>
you are passing the iterated picture as an attribute. In the inserted JSP
pages you do a t:importAttribute first, then you use it as you usually do.


Hm.

But in this case, the definition-name "dynamic" ist still hardcoded into the forEach-loop in "list.jsp". That is, waht I am trying to avoid, because I want to reuse "list.jsp" for several definitions, that all use the same template "list.jsp", but are decorating it with different definitions of "dynamic".

I just noticed, that there was a type-mistake in a central part of my simplified example (wrong variable-name). Additionally, my simplified example might have been to simple. Therefore I think, it is better, if I describe my real setup:


Beneath is an extract from my tiles-defs.xml.

"/WEB-INF/templates/fotos.jsp" is the template, which iterates through the list of pictures. In the fotos.jsp-template, there is an insertAttribute-Tag:

<c:forEach var="picture" items="${page.pictures}">
  <!-- Works only, when I push the variable to request-scope -->
  <c:set var="picture" scope="request" value="${picture}"/>
  <li>
    <!-- other "static" stuff -->
    <t:insertAttribute name="extralinks" ignore="true"/>
  </li>
</c:forEach>

I am trying to change the definition "extralinks", that is inserted by that Tag - _without_ altering the insertAttribute-Tag inside fotos.jsp (because, then I would have maintain multiple slightly different versions of that template).

And the problem is, that the definition (or template), that is inserted as attribute "extralinks", has to pick up the JSTL-variable "picture" of the current forEach-Loop.

Here is the extract of my tiles-defs.xml
----------------------
<definition name="browser/index" extends="index">
  <put-attribute name="robots" value="noindex,nofollow"/>
  <put-attribute name="content">
    <definition template="/WEB-INF/templates/index.jsp">
      <put-attribute name="fotos">
        <definition template="/WEB-INF/templates/fotos.jsp">
          <put-attribute name="extralinks" cascade="true">
            <definition template="/WEB-INF/templates/select.jsp">
              <put-attribute name="picture" expression="${picture}"/>
            </definition>
          </put-attribute>
        </definition>
      </put-attribute>
    </definition>
  </put-attribute>
</definition>

<definition name="selection/index" extends="index">
  <put-attribute name="content">
    <definition template="/WEB-INF/templates/index.jsp">
      <put-attribute name="fotos">
        <definition template="/WEB-INF/templates/fotos.jsp">
          <put-attribute name="extralinks" cascade="true">
            <definition template="/WEB-INF/templates/edit.jsp">
              <put-attribute name="picture" expression="${picture}"/>
            </definition>
          </put-attribute>
        </definition>
      </put-attribute>
    </definition>
  </put-attribute>
</definition>

<definition name="story/index" extends="index">
  <put-attribute name="content">
    <definition template="/WEB-INF/templates/index.jsp">
<put-attribute name="fotos" value="/WEB-INF/templates/fotos.jsp" type="template"/> <put-attribute name="fblike" value="/WEB-INF/templates/fblike.jsp" type="template"/>
    </definition>
  </put-attribute>
</definition>
-------------------

The first definition ("browser/index") inserts a definition, that uses the template "/WEB-INF/templates/select.jsp" to render the specialised links. The third defintion ("selection/index") inserts a definition, that uses the template ".../edit.jsp". The last defintion ("story/index") doese not define "extralinks", so that there are renderd no extralinks.


The inserted definitions (or templates) have to pick up the "picture"-variable, to be able to render the links. Therefore, I am trying to pick that variable up by EL, which does only work, if I push the variable to request-scope.

Because of your previous answers, I now understand, why that is only working, when I push the variable to request-scope. But it is not very elegant, to push it there, because that might lead to name-clashes later on.

So I am looking for another approach, to get the JSTL-variable "picture" from the forEach-loop into the templates, which are inserted as "extralinks" by the insertAttribute-Tag.


Greetings kai

Reply via email to