You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Kai <ka...@ich-geh-kaputt.de> on 2011/10/08 21:39:50 UTC
EL-Expression in definition ignores page-scope
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
Re: EL-Expression in definition ignores page-scope
Posted by Kai <ka...@ich-geh-kaputt.de>.
Am 10.10.2011 17:58, schrieb Kai:
Sorry, I was in a hurry, when I was writing this...
>> No. As I understand, you have two choices:
>> * defining several definitions using list.jsp as a template page, in
>> which
>> the "dynamic" attribute is redefined each time (but probably this is what
>> you are trying to avoid, or not?);
> No, I am only trying to define several versions of the template
> list.jsp, which only differ in the <t:insertAttribute
> template="dynamic-X.jsp">-part.
>
I meant:
I am only trying to _avoid_ several versions of the template "list.jsp",
that only differ in the insertAttribute-part.
> Indead, defining several definitions using list.jsp as a template is
And:
Indead, defining several definitions, that are using the same "list.jsp"
as template is ecactly, what I am trying to do.
> exactly, what I am trying to do. I only don't know, how to feed in the
> dynamicly "computed" picture-instance, which is only accessible in the
> forEach-Loop!
>
>> * 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...
Greetings Kai
Re: EL-Expression in definition ignores page-scope
Posted by Antonio Petrelli <an...@gmail.com>.
2011/10/12 Kai <ka...@ich-geh-kaputt.de>
> Am 11.10.2011 11:16, schrieb Antonio Petrelli:
>
>> See my modifications inline.
>>
>> Thank you very much!
> That solved my problem :)
I'm happy of it :-)
I think, I am slowly beginnig to realise, how much stereoids tiles has taken
> ;)
>
LOL
Have a nice day
Antonio
Re: EL-Expression in definition ignores page-scope
Posted by Kai <ka...@ich-geh-kaputt.de>.
Am 11.10.2011 11:16, schrieb Antonio Petrelli:
> See my modifications inline.
>
Thank you very much!
That solved my problem :)
>
> <c:forEach var="picture" items="${page.pictures}">
> <li>
> <!-- other "static" stuff -->
> <t:insertAttribute name="extralinks" ignore="true">
> <t:putAttribute name="picture" value="${picture}" />
> </t:insertAttribute>
> </li>
> </c:forEach>
>
I wasn't aware, that I can put a <t:putAttribute> inside a
<t:insertAttribute>. And because of that, I missunderstood that
solution, as you first mentioned it in your second answer. I always
thought, that this is only possible with <t:insertDefinition> or
<t:insertTemplate>.
I think, I am slowly beginnig to realise, how much stereoids tiles has
taken ;)
Greetings
kai
Re: EL-Expression in definition ignores page-scope
Posted by Antonio Petrelli <an...@gmail.com>.
See my modifications inline.
2011/10/11 Kai <ka...@ich-geh-kaputt.de>
> <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>
>
<c:forEach var="picture" items="${page.pictures}">
<li>
<!-- other "static" stuff -->
<t:insertAttribute name="extralinks" ignore="true">
<t:putAttribute name="picture" value="${picture}" />
</t:insertAttribute>
</li>
</c:forEach>
> <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="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"
value="/WEB-INF/templates/**select.jsp" />
</definition>
</put-attribute>
</definition>
</put-attribute>
</definition>
For similar definitions use this pattern.
I suppose that, in select.jsp and similar, you have a t:importAttribute. If
yes, you should not need to change anything there.
Antonio
Re: EL-Expression in definition ignores page-scope
Posted by Kai <ka...@ich-geh-kaputt.de>.
Am 11.10.2011 09:17, schrieb Antonio Petrelli:
> 2011/10/10 Kai<ka...@ich-geh-kaputt.de>
>>> * 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
Re: EL-Expression in definition ignores page-scope
Posted by Antonio Petrelli <an...@gmail.com>.
2011/10/10 Kai <ka...@ich-geh-kaputt.de>
> Am 10.10.2011 15:12, schrieb Antonio Petrelli:
>
> Do you suggest to define an additional attribute in the specialised
>>> definition, which holds the path to the template and then inject that
>>> attribute to the template-attribute of the<t:insertAttribute>-Tag?
>>>
>>>
>> No. As I understand, you have two choices:
>> * defining several definitions using list.jsp as a template page, in which
>> the "dynamic" attribute is redefined each time (but probably this is what
>> you are trying to avoid, or not?);
>>
> No, I am only trying to define several versions of the template list.jsp,
> which only differ in the <t:insertAttribute template="dynamic-X.jsp">-**
> part.
>
> Indead, defining several definitions using list.jsp as a template is
> exactly, what I am trying to do. I only don't know, how to feed in the
> dynamicly "computed" picture-instance, which is only accessible in the
> forEach-Loop!
>
>
> * 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.
Antonio
>
>
> But in my view, it would be a really nice feature, if it would work how I
>>> had it expected to. It would ease the understandig of how the
>>> EL-Expressions
>>> in definitions work and it would hugely widen the applicability of
>>> EL-Expressions in definitions.
>>>
>> [..]
>
>
>> I think that it would be confusing the way you are interpreting use of EL
>> in
>> Tiles. After all, Tiles is<jsp:include> on steroids and usually it
>> behaves
>> as<jsp:include> behaves. And anyway, I doubt that it is even feasible.
>> However, Tiles has already a well-done scope management for attributes, in
>> which attributes in one included page are not visible outside (the
>> implementation is essentially a stack) with the exception of cascaded
>> attributes. Something like this is not available in EL out-of-the-box,
>> because it relies on the 4 standard scopes (page, request, session,
>> application). IIRC there is a way to create additional scopes but,
>> sincerely, I don't know how.
>>
>> Yeah, you are right.
>
> Meanwhile, I debugged a little more around in the <t:insertAttribute> and I
> noticed the jsp:include-style there. I wasn't aware of that before...
>
>
>
> Greetings kai
>
Re: EL-Expression in definition ignores page-scope
Posted by Kai <ka...@ich-geh-kaputt.de>.
Am 10.10.2011 15:12, schrieb Antonio Petrelli:
>> Do you suggest to define an additional attribute in the specialised
>> definition, which holds the path to the template and then inject that
>> attribute to the template-attribute of the<t:insertAttribute>-Tag?
>>
>
> No. As I understand, you have two choices:
> * defining several definitions using list.jsp as a template page, in which
> the "dynamic" attribute is redefined each time (but probably this is what
> you are trying to avoid, or not?);
No, I am only trying to define several versions of the template
list.jsp, which only differ in the <t:insertAttribute
template="dynamic-X.jsp">-part.
Indead, defining several definitions using list.jsp as a template is
exactly, what I am trying to do. I only don't know, how to feed in the
dynamicly "computed" picture-instance, which is only accessible in the
forEach-Loop!
> * 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...
>> But in my view, it would be a really nice feature, if it would work how I
>> had it expected to. It would ease the understandig of how the EL-Expressions
>> in definitions work and it would hugely widen the applicability of
>> EL-Expressions in definitions.
[..]
>
> I think that it would be confusing the way you are interpreting use of EL in
> Tiles. After all, Tiles is<jsp:include> on steroids and usually it behaves
> as<jsp:include> behaves. And anyway, I doubt that it is even feasible.
> However, Tiles has already a well-done scope management for attributes, in
> which attributes in one included page are not visible outside (the
> implementation is essentially a stack) with the exception of cascaded
> attributes. Something like this is not available in EL out-of-the-box,
> because it relies on the 4 standard scopes (page, request, session,
> application). IIRC there is a way to create additional scopes but,
> sincerely, I don't know how.
>
Yeah, you are right.
Meanwhile, I debugged a little more around in the <t:insertAttribute>
and I noticed the jsp:include-style there. I wasn't aware of that before...
Greetings kai
Re: EL-Expression in definition ignores page-scope
Posted by Antonio Petrelli <an...@gmail.com>.
2011/10/10 Kai <ka...@ich-geh-kaputt.de>
> If yes, list.jsp can be reused anywhere (I mean for any kind of picture
>> template), as long as you identify all the needed data that each piece
>> needs, and pass them always, even if they don't use it.
>>
>> And how do I change the called template in the XML-definitions?
> Do you suggest to define an additional attribute in the specialised
> definition, which holds the path to the template and then inject that
> attribute to the template-attribute of the <t:insertAttribute>-Tag?
>
No. As I understand, you have two choices:
* defining several definitions using list.jsp as a template page, in which
the "dynamic" attribute is redefined each time (but probably this is what
you are trying to avoid, or not?);
* using a view preparer for the definition that computes the attribute to
put as "dynamic" attribute.
> [..]
>
> I had expected, that the EL would behave in the same way it behaves, when
>>> it is written in the<t:insertAttribute>-Tag like in your last mail...
>>>
>>>
>> No, in my example, the EL expression is evaluated then passed to the
>> attribute. In your example, the attribute is rendered and, when rendering,
>> the EL expression is evaluated (to nothing).
>>
>> O.k.
> I think, I got that now.
>
> But in my view, it would be a really nice feature, if it would work how I
> had it expected to. It would ease the understandig of how the EL-Expressions
> in definitions work and it would hugely widen the applicability of
> EL-Expressions in definitions.
>
> I would like to try to implement that behaviour. But I don't know, if I am
> able to find the right lines of code, to alter. So far, I debuged my way
> into the class, that creates the TilesApplicationContext for the evaluation
> of the expression. But I'm lost there - somwhere...
>
I think that it would be confusing the way you are interpreting use of EL in
Tiles. After all, Tiles is <jsp:include> on steroids and usually it behaves
as <jsp:include> behaves. And anyway, I doubt that it is even feasible.
However, Tiles has already a well-done scope management for attributes, in
which attributes in one included page are not visible outside (the
implementation is essentially a stack) with the exception of cascaded
attributes. Something like this is not available in EL out-of-the-box,
because it relies on the 4 standard scopes (page, request, session,
application). IIRC there is a way to create additional scopes but,
sincerely, I don't know how.
Antonio
Re: EL-Expression in definition ignores page-scope
Posted by Kai <ka...@ich-geh-kaputt.de>.
Am 10.10.2011 12:22, schrieb Antonio Petrelli:
> Very interesting and challenging question.
Yes :)
> I suppose that these "dynamic" pieces have something in common (e.g. an id,
> an URL of the picture). This data can be passed as an attribute. The rest,
> i.e. the specialized links/operations that you do on each picture, should be
> computed internally in each piece, is it right?
The forEach-Tag iterates over a set of instances of the class picture.
These Instances hold every information, that is needed to compute the
links etc., so the actual picture-instance in loop x is the only
information, which has to be passed to the called template.
So I think, the answer is jes.
> If yes, list.jsp can be reused anywhere (I mean for any kind of picture
> template), as long as you identify all the needed data that each piece
> needs, and pass them always, even if they don't use it.
>
And how do I change the called template in the XML-definitions?
Do you suggest to define an additional attribute in the specialised
definition, which holds the path to the template and then inject that
attribute to the template-attribute of the <t:insertAttribute>-Tag?
[..]
>> I had expected, that the EL would behave in the same way it behaves, when
>> it is written in the<t:insertAttribute>-Tag like in your last mail...
>>
>
> No, in my example, the EL expression is evaluated then passed to the
> attribute. In your example, the attribute is rendered and, when rendering,
> the EL expression is evaluated (to nothing).
>
O.k.
I think, I got that now.
But in my view, it would be a really nice feature, if it would work how
I had it expected to. It would ease the understandig of how the
EL-Expressions in definitions work and it would hugely widen the
applicability of EL-Expressions in definitions.
I would like to try to implement that behaviour. But I don't know, if I
am able to find the right lines of code, to alter. So far, I debuged my
way into the class, that creates the TilesApplicationContext for the
evaluation of the expression. But I'm lost there - somwhere...
Greetings kai
> Antonio
>
Re: EL-Expression in definition ignores page-scope
Posted by Antonio Petrelli <an...@gmail.com>.
2011/10/10 Kai <ka...@ich-geh-kaputt.de>
> Am 10.10.2011 10:11, schrieb Antonio Petrelli:
>
> 2011/10/10 Kai<ka...@ich-geh-kaputt.de>
>>
>> In my real problem, list.jsp ist much more complex and I want to reuse it
>>> on several pages. The only part of list.jsp which changes from page to
>>> page
>>> is the part in dynamic.jsp, which is bind in in the definition.
>>>
>>> Therefore I cannot "hartcode" the Template with a<t:insertAttribute>-Tag
>>> inside the list.jsp-Template. Because then, I would have to copy list.jsp
>>> for every page and would end up with several versions of list.jsp, which
>>> only differ in this one<t:insertAttribute>-Tag. That would not be good,
>>> because I would have to edit several nearly identical copies, if I want
>>> to
>>> change list.jsp later on!
>>>
>>>
>> Try to explain your use case further, maybe there are better solutions
>> (e.g.
>> ViewPreparer).
>>
>> I am programming a picture-album.
>
> There are severale pages, which are listing a set of pictures. For example,
> an import, a selected set of pictues, a picture-story, ... The markup for
> these picture-listings basically is the same on all these pages. Therefore,
> I would like to use one single template for that markup (the list.jsp in my
> simplified example).
>
> But on every page-type, there are different Links for further actions
> beneath each listed picture. On the import-page there would be a
> rotate-link. On the page that lists selected pictures, there would be the
> links remove, move up and move down. On the picture-story-page there would
> be no links at all... Each set of links is a different sub-template (the
> dynamic.jsp in my simplified example).
>
> Hence, I am looking for a way to embed different templates inside the
> base-template.
>
> A perfect match for one base-definition, which uses list.jsp as template,
> and a set of special definitions, which inherit from the base definition and
> overwrite an attribute (the attribute dynamic in my example), to insert an
> inner template with the specific links.
>
> But then, on each insertion of that inner template, the inner template has
> to know the actual picture of the set of pictures, the outer template is
> iterating over.
>
> That would work perfectly, if I would use <t:insertAttribute> in the outer
> template, as you have shown in your last mail. But I cannot do that, because
> I would need several versions of the outer template then. One for each
> specialised set of links, because for each set of specialised links, another
> template has to be included!
>
> Hence, I tried to pick up the variable with an EL-Expression in the
> definition...
Very interesting and challenging question.
I suppose that these "dynamic" pieces have something in common (e.g. an id,
an URL of the picture). This data can be passed as an attribute. The rest,
i.e. the specialized links/operations that you do on each picture, should be
computed internally in each piece, is it right?
If yes, list.jsp can be reused anywhere (I mean for any kind of picture
template), as long as you identify all the needed data that each piece
needs, and pass them always, even if they don't use it.
> But I have understand, that the EL in the XML-definition is evaluated, when
>>> the definition is inserted. In case of the nested anonymous definition,
>>> that
>>> would happen while the forEach-Loop is renderd.
>>> Therefore I had concluded that the EL sees the environment of that moment
>>> and that page.
>>>
>>>
>> It's true that EL is evaluated when the inserted page is rendered, but the
>> *value* of the attribute is in the page that includes it.
>>
>> Oh.
>
> I had expected, that the EL would behave in the same way it behaves, when
> it is written in the <t:insertAttribute>-Tag like in your last mail...
>
No, in my example, the EL expression is evaluated then passed to the
attribute. In your example, the attribute is rendered and, when rendering,
the EL expression is evaluated (to nothing).
Antonio
Re: EL-Expression in definition ignores page-scope
Posted by Kai <ka...@ich-geh-kaputt.de>.
Am 10.10.2011 10:11, schrieb Antonio Petrelli:
> 2011/10/10 Kai<ka...@ich-geh-kaputt.de>
>
>> In my real problem, list.jsp ist much more complex and I want to reuse it
>> on several pages. The only part of list.jsp which changes from page to page
>> is the part in dynamic.jsp, which is bind in in the definition.
>>
>> Therefore I cannot "hartcode" the Template with a<t:insertAttribute>-Tag
>> inside the list.jsp-Template. Because then, I would have to copy list.jsp
>> for every page and would end up with several versions of list.jsp, which
>> only differ in this one<t:insertAttribute>-Tag. That would not be good,
>> because I would have to edit several nearly identical copies, if I want to
>> change list.jsp later on!
>>
>
> Try to explain your use case further, maybe there are better solutions (e.g.
> ViewPreparer).
>
I am programming a picture-album.
There are severale pages, which are listing a set of pictures. For
example, an import, a selected set of pictues, a picture-story, ... The
markup for these picture-listings basically is the same on all these
pages. Therefore, I would like to use one single template for that
markup (the list.jsp in my simplified example).
But on every page-type, there are different Links for further actions
beneath each listed picture. On the import-page there would be a
rotate-link. On the page that lists selected pictures, there would be
the links remove, move up and move down. On the picture-story-page there
would be no links at all... Each set of links is a different
sub-template (the dynamic.jsp in my simplified example).
Hence, I am looking for a way to embed different templates inside the
base-template.
A perfect match for one base-definition, which uses list.jsp as
template, and a set of special definitions, which inherit from the base
definition and overwrite an attribute (the attribute dynamic in my
example), to insert an inner template with the specific links.
But then, on each insertion of that inner template, the inner template
has to know the actual picture of the set of pictures, the outer
template is iterating over.
That would work perfectly, if I would use <t:insertAttribute> in the
outer template, as you have shown in your last mail. But I cannot do
that, because I would need several versions of the outer template then.
One for each specialised set of links, because for each set of
specialised links, another template has to be included!
Hence, I tried to pick up the variable with an EL-Expression in the
definition...
>> But I have understand, that the EL in the XML-definition is evaluated, when
>> the definition is inserted. In case of the nested anonymous definition, that
>> would happen while the forEach-Loop is renderd.
>> Therefore I had concluded that the EL sees the environment of that moment
>> and that page.
>>
>
> It's true that EL is evaluated when the inserted page is rendered, but the
> *value* of the attribute is in the page that includes it.
>
Oh.
I had expected, that the EL would behave in the same way it behaves,
when it is written in the <t:insertAttribute>-Tag like in your last mail...
Greetings kai
Re: EL-Expression in definition ignores page-scope
Posted by Antonio Petrelli <an...@gmail.com>.
2011/10/10 Kai <ka...@ich-geh-kaputt.de>
> In my real problem, list.jsp ist much more complex and I want to reuse it
> on several pages. The only part of list.jsp which changes from page to page
> is the part in dynamic.jsp, which is bind in in the definition.
>
> Therefore I cannot "hartcode" the Template with a <t:insertAttribute>-Tag
> inside the list.jsp-Template. Because then, I would have to copy list.jsp
> for every page and would end up with several versions of list.jsp, which
> only differ in this one <t:insertAttribute>-Tag. That would not be good,
> because I would have to edit several nearly identical copies, if I want to
> change list.jsp later on!
>
Try to explain your use case further, maybe there are better solutions (e.g.
ViewPreparer).
> The problem is that list.jsp and dynamic.jsp are two different pages. Just
>> like<jsp:include> paged-scope attributes in including page are not
>> visible
>> in the included one (and viceversa).
>>
>
> Yes, that's true!
>
> But I have understand, that the EL in the XML-definition is evaluated, when
> the definition is inserted. In case of the nested anonymous definition, that
> would happen while the forEach-Loop is renderd.
> Therefore I had concluded that the EL sees the environment of that moment
> and that page.
>
It's true that EL is evaluated when the inserted page is rendered, but the
*value* of the attribute is in the page that includes it.
> The later would - in my view - be a bug, or, to put it in other words:, it
> would be nice feature to have, if the EL would see the page-scope variables
> or even the nested scoped variables of the moment, where it is inserted.
> Because, then the EL in the definition would behave exactly the same way, as
> the EL in your solution above!
>
Not a Tiles problem, anyway.
Antonio
Re: EL-Expression in definition ignores page-scope
Posted by Kai <ka...@ich-geh-kaputt.de>.
Am 09.10.2011 19:42, schrieb Antonio Petrelli:
> However there is a more elegant way to pass attributes.
> In list.jsp:
>
> <c:forEach var="i" begin="1" end="10" step="1">
> <li><em>Loop #${i}:</em>
> <t:insertAttribute name="dynamic">
> <t:putAttribute name="var" value="${i}" />
> </t:insertAttribute></li>
> </c:forEach>
>
> Then the "put-attribute" in the definition XML file is no more needed.
>
Thanks for your answer!
I know, that I could use <t:insertAttribute> to solve the problem in my
simplified example. But I could not use it, to achieve, what I really
want to do.
In my real problem, list.jsp ist much more complex and I want to reuse
it on several pages. The only part of list.jsp which changes from page
to page is the part in dynamic.jsp, which is bind in in the definition.
Therefore I cannot "hartcode" the Template with a
<t:insertAttribute>-Tag inside the list.jsp-Template. Because then, I
would have to copy list.jsp for every page and would end up with several
versions of list.jsp, which only differ in this one
<t:insertAttribute>-Tag. That would not be good, because I would have to
edit several nearly identical copies, if I want to change list.jsp later on!
Am 09.10.2011 19:42, schrieb Antonio Petrelli:
> The problem is that list.jsp and dynamic.jsp are two different pages. Just
> like<jsp:include> paged-scope attributes in including page are not visible
> in the included one (and viceversa).
Yes, that's true!
But I have understand, that the EL in the XML-definition is evaluated,
when the definition is inserted. In case of the nested anonymous
definition, that would happen while the forEach-Loop is renderd.
Therefore I had concluded that the EL sees the environment of that
moment and that page.
Apparently the EL sees the environment of that moment, because it picks
up the changed variable i, when I push that variable to request scope.
But perhaps the EL does not see the environment of that page!
The later would - in my view - be a bug, or, to put it in other words:,
it would be nice feature to have, if the EL would see the page-scope
variables or even the nested scoped variables of the moment, where it is
inserted. Because, then the EL in the definition would behave exactly
the same way, as the EL in your solution above!
Greetings Kai
Re: EL-Expression in definition ignores page-scope
Posted by Antonio Petrelli <an...@gmail.com>.
2011/10/9 Kai <ka...@ich-geh-kaputt.de>
> Am 09.10.2011 14:02, schrieb Antonio Petrelli:
>
> 2011/10/8 Kai<ka...@ich-geh-kaputt.de>
>>
>> <c:forEach var="i" begin="1" end="10" step="1">
>>> ...
>>> 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?
>>>
>>>
>> You're missing how the "var" attribute works:
>> http://download.oracle.com/**javaee/5/jstl/1.1/docs/**
>> tlddocs/c/forEach.html<http://download.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/forEach.html>
>> At the "var" attribute I read:
>> <snip>
>> Name of the exported scoped variable for the current item of the
>> iteration.
>> This scoped variable has nested visibility. Its type depends on the object
>> of the underlying collection.
>> </snip>
>>
>> So it's got nested visibility, not page.
>>
>> You are right, I missed that one.
>
> Thank you for your help so far :)
>
>
> But unfortunatly, it's not the only problem.
> I already tried to push the forEach-variable to page-scop with
>
> <c:set var="i" value="${i}" scope="page"/>
>
> But that does not help either!
> The EL-Expression in the definition only picks it up, if I push the
> variable to request-scope with
>
>
> <c:set var="i" value="${i}" scope="request"/>
>
> (I double-checked, that the variable is really picked up by the
> EL-Expression and is not only visible inside the other template, because it
> was pushed inside request-scope. When in request-scope, the expression picks
> up the variable, when in page-scope not!)
>
The problem is that list.jsp and dynamic.jsp are two different pages. Just
like <jsp:include> paged-scope attributes in including page are not visible
in the included one (and viceversa).
However there is a more elegant way to pass attributes.
In list.jsp:
<c:forEach var="i" begin="1" end="10" step="1">
<li><em>Loop #${i}:</em>
<t:insertAttribute name="dynamic">
<t:putAttribute name="var" value="${i}" />
</t:insertAttribute></li>
</c:forEach>
Then the "put-attribute" in the definition XML file is no more needed.
HTH
Antonio
Re: EL-Expression in definition ignores page-scope
Posted by Kai <ka...@ich-geh-kaputt.de>.
Am 09.10.2011 14:02, schrieb Antonio Petrelli:
> 2011/10/8 Kai<ka...@ich-geh-kaputt.de>
>
>> <c:forEach var="i" begin="1" end="10" step="1">
>> ...
>> 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?
>>
>
> You're missing how the "var" attribute works:
> http://download.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/forEach.html
> At the "var" attribute I read:
> <snip>
> Name of the exported scoped variable for the current item of the iteration.
> This scoped variable has nested visibility. Its type depends on the object
> of the underlying collection.
> </snip>
>
> So it's got nested visibility, not page.
>
You are right, I missed that one.
Thank you for your help so far :)
But unfortunatly, it's not the only problem.
I already tried to push the forEach-variable to page-scop with
<c:set var="i" value="${i}" scope="page"/>
But that does not help either!
The EL-Expression in the definition only picks it up, if I push the
variable to request-scope with
<c:set var="i" value="${i}" scope="request"/>
(I double-checked, that the variable is really picked up by the
EL-Expression and is not only visible inside the other template, because
it was pushed inside request-scope. When in request-scope, the
expression picks up the variable, when in page-scope not!)
Greetings Kai
Re: EL-Expression in definition ignores page-scope
Posted by Antonio Petrelli <an...@gmail.com>.
2011/10/8 Kai <ka...@ich-geh-kaputt.de>
> <c:forEach var="i" begin="1" end="10" step="1">
> ...
> 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?
>
You're missing how the "var" attribute works:
http://download.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/c/forEach.html
At the "var" attribute I read:
<snip>
Name of the exported scoped variable for the current item of the iteration.
This scoped variable has nested visibility. Its type depends on the object
of the underlying collection.
</snip>
So it's got nested visibility, not page.
Antonio