velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nat...@esha.com>
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
#foreach?
>
> ApplicationResources.properties 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)

ApplicationResources.properties contains:
list.size=3
list.1=a
list.2=b
list.3=c

your template:
<select>
#foreach( $i in [1..$math.toInt($msg.get('list.size')] )
    <option>$msg.get("list.$i")</option>
#end
</select>

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
nathan@esha.com


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


Mime
View raw message