struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Rank <>
Subject Re: [tiles 2] Accessing items from a putList?
Date Sun, 31 Dec 2006 18:21:54 GMT
I figured out a way to get by without using the Core JSTL "forEach"  
tag. Antonio, as you state, I can use any method of iteration I  
choose. In my case, my goal was to use the struts "iterator" tag.  
Code that works follows:


<tiles:importAttribute name="myPutList" scope="request"/>

<s:iterator value="#request['myPutList']" id="part" >
	<s:set value="#part" name="p"/>
	<tiles:insertDefinition name="${p}" />

However, this seems a little less elegant than using the Core JSTL  
forEach tag. But, does it work? Yes. Is it ok? Yes. Is it somewhat  
confusing to mix the syntaxes, scopes and contexts? Yes.

I find the context / variable scoping to be more of a challenge to  
deal with than anything else. In this example, in order to access the  
imported tiles attribute on the page, I need to set it into a scope  
that the struts tags have access to. Here , I just put it into the  
request scope. Then, once the struts "iterator" tag loops through the  
list, it sets the values into it's own OGNL context, which the tiles  
tags cannot access. Then, I have to bring it back, once again, into a  
scope that the tiles tags can access. This requires explicitly  
placing the value into an accessible context with the "set" tag.  
Finally, I can insert the tiles definition with EL syntax.

For me, I think the challenge will be figuring out a set of  
conventions and self-imposed rules for when it's appropriate to use  
Struts tags with OGNL syntax, and when to use EL and JSTL. It's nice  
to have the flexibility to put it all together, but it definitely  
increases the amount of knowledge required to assemble a page of  
code. Just my opinion.

Thanks again for the help,

Eric Rank

On Dec 31, 2006, at 4:24 AM, Antonio Petrelli wrote:

> Eric Rank ha scritto:
>> Hi all,
>> I am trying to insert items from a putList defined in my tiles.xml  
>> file in a template file. The only way that I can seem to do it is  
>> by using the following process
>> 1. make the putList 'List' accessible on the page with  
>> <tiles:useAttribute name="myPutList" />
>> 2. sending that variable in to a JSTL Core taglib forEach loop
>> 3. using <tiles:insertDefinition name="${putListItem}" />
> I think your code is perfect, so why don't you like it?
> Tiles 2 does not depend on Struts anymore, so the "best practice"  
> is to use the most generic tag libraries, that is JSTL.
> Instead of <tiles:useAttribute> you can use <tiles:importAttribute>  
> that does not create a scripting variable, but only a page context  
> attribute.
> Anyway you can use all the "iterate" tags you like.
> Antonio
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message