velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <>
Subject "safe" way to get index of current item in a foreach loop?
Date Wed, 01 Oct 2003 15:59:57 GMT
I have velocity code that looks similar to this.

#foreach ($anAccount in $accountsList)


#end ## foreach anAccount

However, I don't want to attach a raw java object to the account parameter.  
Instead I want to attach the current index of the item in $accountsList, 
which is an ArrayList object. 

[$accountsList is persistent across the request/response loop, so please 
don't get sidetracked by that.]

I know I can do something like the following with $velocityCount, but I 
don't know if $velocityCount is guaranteed to match the indexes of my 
ArrayList (and lacking documentation to that effect, I assume it is not.)

#foreach ($anAccount in $accountsList)


#end ## foreach anAccount

[I also know that I would have to set counter.initial.value = 0 in the file or otherwise account for the starting value of 

Is this a safe way to go?   Is this the best way to go?  How do people 
generally identify a specific java object inside a #foreach, particularly as 
html href or form action?



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

View raw message