velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Nocera" <rnoc...@neosllc.com>
Subject RE: "safe" way to get index of current item in a foreach loop?
Date Thu, 02 Oct 2003 13:32:59 GMT
Mike,

I have used $velocityCount for that type of thing without any problems.
Maybe I just assumed it would match the index in my collection, but it
always has.

Robert Nocera
[NEOS]
www.neosllc.com

  


-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@alaska.net] 
Sent: Wednesday, October 01, 2003 12:00 PM
To: velocity-user@jakarta.apache.org
Subject: "safe" way to get index of current item in a foreach loop?

I have velocity code that looks similar to this.

#foreach ($anAccount in $accountsList)

	<a 
href="${link.setAction('ViewAccountBill').addQueryData('account',$anAcco
unt)}">
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',$veloci
tyCount)}">
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



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