velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jesus Zazueta <>
Subject Binding a variable collection inside a Spring enabled Velocity template
Date Mon, 15 Aug 2011 20:24:37 GMT


Suppose I have the following Spring form backing object fed to a Velocity
1.5 template:

public class Bucket {

    String data1;
    String data2;
    String data3;
    String data4;

    // getters setters blah blah...

I'd like to bind these four String attributes to the following java.util.Map
of Strings, inside four drop down single select controls:

"a" : "1"
"b" : "2"
"c" : "3"
"d" : "4"

If inside my page's controller Model, I name the backing object "boData",
and the value map "labelKeys", velocity can bind the backing object's
properties for me:

#springFormSingleSelect( "boData.data1" $labelKeys "")
#springFormSingleSelect( "boData.data2" $labelKeys "")
#springFormSingleSelect( "boData.data3" $labelKeys "")
#springFormSingleSelect( "boData.data4" $labelKeys "")

However, is there a way to avoid invoking #springFormSingleSelect four
times? I mean, there's a pattern here, but I can't see the way to express it
in Velocity's terms.

If for example, I defined instead these four String attributes inside class
Bucket as a Java array, or a java.util.List, how could I tell velocity that
I need it to bind a drop down single select control for each element in the

public class Bucket {
    List<String> dataItems = new ArrayList<String>();
    // getter, setter...

I thank you for any insight you could provide!

View this message in context:
Sent from the Velocity - User mailing list archive at

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

View raw message