velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <>
Subject Re: A Dynamic ArrayList Literal?
Date Wed, 14 Jul 2004 21:40:58 GMT said:
> I would like to store an ArrayList literal in a Velocity variable and then
> use the stored ArrayList literal to establish a new ArrayList (and its
> contents),
> e.g. I'd like to do something like:
> #set($names = '["Bill","Harry","Chris","Sue"]')
> #set($namesArrayList = $names)
> #foreach($name in $namesArrayList)
>    $name
> #end
> However, the above VTL results in $namesArrayList
> being a variable (not an ArrayList) and hence the
> foreach directive effectively does nothing.
> Is there a way to do what I am attempting here?
> In the second #set directive, I want $names to be
> evaluated (substitution occurs) before the assignment
> takes place.

why on earth would you want to do a weird thing like that?!?

ok, avoiding that obvious question for a moment...  ;-)

i think your only real hope here is to use a tool.  If you don't want to write
your own array parsing tool, then you might be able to get away with using
either the RenderTool or ViewRenderTool in Velocity-Tools (or something like
them) as follows:

#set( $badidea = '#set( $namesArrayList = ["Bill","Chris", "Sue"] )' )
#foreach( $name in $namesArrayList )

however, please note that i have not actually tried doing this and i think
that it's ugly as hell.  i don't know what problem you're trying to solve, but
there really must be a better way.  seriously, even hacking up a little
ListParserTool would be a better solution, and shouldn't take too long to do.

Nathan Bubna

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

View raw message