Wow!

OK, now I get it. Yes, I'm using T3.x. I never thought about that use
for the index parameter, I had used only to display the current row's
number. Your solution is very attractive because it will be trivial to
add new columns to the table in case I need to, which was a major
problem with the solution I was devising. It was only a matter of
thinking about OGNL expressions in a different way than I always use
them.

Thanks a lot, Mark.

Regards,

Dario


On 2/21/07, Mark Stang <[EMAIL PROTECTED]> wrote:
Dario,
The Foreach component T3.x, which I presume you are using (If you are not,check the 
components for your version), contains a parameter named "index".

index   int     out     no              Used to store the index of the current 
value within the stream of elements provided by the source parameter. The index 
parameter is explicitly updated before the value parameter.

If you set it:

index="ognl:currentIndex"

Then as Tapestry iterates over the list that was passed to the "Foreach" it will call 
"setCurrentIndex" with the current index.  This happens at the top of the loop.  So, in the body of the 
Foreach for a particular <td> you can call getList1().  Since you are not passing in a value/parameter to 
getList1(), how does it know what item in the list to return?  Inside the method, you use "currentIndex" 
to pick the item in the list to return.

Basically, the Foreach knows what iteration it is on.  You can have it pass 
that value back to your Java Class with a setter. Whenever you call any of the 
getList methods, they use the value passed in by the Foreach.

HTH,

Mark

Mark J. Stang
Senior Engineer/Architect
office: +1 303.468.2900
mobile: +1 303.507.2833
Ping Identity



-----Original Message-----
From: Darío Vasconcelos [mailto:[EMAIL PROTECTED]
Sent: Wed 2/21/2007 3:06 PM
To: Tapestry users
Subject: Re: Foreach, iterate over several collections at once

Sorry Mark,

I didn't quite understand what you're saying, although it sounds very
interesting. I can't imagine how I could make Foreach update the
current value for each list, using only one Foreach. Or could I use
nested Foreachs? If you would be so kind as to give me a small
example, I would be very grateful...

Dario.

On 2/21/07, Mark Stang <[EMAIL PROTECTED]> wrote:
> Hi,
> The Foreach can call your class with the "current" index and set it.  The "getters" use 
that value to return the "current" value for each list.
>
> HTH,
>
> Mark
>
> Mark J. Stang
> Senior Engineer/Architect
> office: +1 303.468.2900
> mobile: +1 303.507.2833
> Ping Identity
>
>
>
> -----Original Message-----
> From: Darío Vasconcelos [mailto:[EMAIL PROTECTED]
> Sent: Wed 2/21/2007 2:43 PM
> To: Tapestry users
> Subject: Foreach, iterate over several collections at once
>
> Hi,
>
> I'm trying to solve a problem that might be trivial in JSP, but I
> can't find a way to do it in Tapestry without some collection munching
> in Java.
>
> My problem is that I have three ArrayLists that hold very similar
> information, and need to be displayed inside the same table. To
> explain this better, let me draw a simple diagram:
>
> HeaderRow1       list1         list2       list3
> HeaderRow2       list2         list2       list3
> HeaderRow3       list3         list2       list3
>
> That is, List1 contains a HashMap with two elements: HeaderRow1 and
> the value for List1. List2 contains also a HashMap with twoelements,
> HeaderRow1 and list2. The same applies to List3.
>
> I'm thinking on using a Foreach for this, but it will only iterate
> over one of the lists, and I **really** need this data to be in the
> same table. Of course, more than just one column per list needs to be
> displayed, my example is a simplification.
>
> The obvious solution is to create a getJoinedTable() method and join
> the three collections into one big ArrayList, but the code isn't nice,
> and since I need to do this for several other pages, the picture is
> not very nice.
>
> What puzzles me is that the solution to this problem in JSP would be
> soooo simple!! There has to be a "Tapestried" way to do it...
>
> Regards,
>
> Dario
>
>
> --
> A zygote is a gamete's way of producing more gametes. This may be the
> purpose of the universe.
>  - Robert A. Heinlein
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>


--
A zygote is a gamete's way of producing more gametes. This may be the
purpose of the universe.
 - Robert A. Heinlein

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
A zygote is a gamete's way of producing more gametes. This may be the
purpose of the universe.
- Robert A. Heinlein

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to