velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <>
Subject Re: Use ApplicationResources property in #foreach
Date Sat, 07 Dec 2002 20:23:28 GMT
x-itus said:
> How can I use a Struts ApplicationResources property as a list in
> contains:
> list=['a', 'b', 'c']
> my velocity template:
> <select>
> #foreach($el in $msg.get('list'))
> <option>$el</option>
> #end
> </select>
> should result in an option list containing 'a', 'b' and 'c'.
> I guess $msg.get('list') returns a string and #foreach will not turn that
> into an array.

yep.  Velocity-Struts' MessageTool only returns application resources as
strings.  unless you want to write yourself a tool to turn the string into a
list, maybe something like this will work for you:  (note that i haven't
tested this code and i am assuming you are including the MathTool as $math) contains:

your template:
#foreach( $i in [1..$math.toInt($msg.get('list.size')] )

yeah, it's not pretty, but if you really need to read a list completely from
the AppResources, then this should work.  again, your other option is to
write your own tool to convert a String into a List.

Nathan Bubna

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

View raw message