Suppose I have the following form backing object for 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 List?
public class Bucket {
List<String> dataItems = new ArrayList<String>();
// getter, setter...
}
I thank you for any insight you could provide!
How about: