velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@alaska.net>
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)

	<a 
href="${link.setAction('ViewAccountBill').addQueryData('account',$anAccount)}">
History</A>

#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)

	<a 
href="${link.setAction('ViewAccountBill').addQueryData('account',$velocityCount)}">
History</A>

#end ## foreach anAccount

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

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?

Thanks,

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message