How can I use the "options" tag with a collection of options stored in my ActionForm bean?

Ted Husted

The properties for options are very confusing, and there's talk on DEV of an alternate tag, optimized to use something like the LabelValue beans.

Here's how to use the current options tag when the LabelValue collection (from the Example) has been stored as a property on the ActionForm. If you want to provide the collection through an ActionForm method, you need to define a scripting variable first.

<bean:define id="myOptions" name="donorForm" 
        property="myOptions" type="java.util.Collection"/>


<html:select property="image">
<html:options collection="myOptions" property="value"

If you wanted to build the list from a static method in your business layer, a simple one could look like this:

    public static String getMyOptions(int image) {
        String text = null;
            switch (image) {
                case -5: text = "Photograph item"; break;
                case -4: text = "Clip from Website"; break;
                case -3: text = "Expect by email"; break;
                case -2: text = "Expect by mail"; break;
                case -1: text = "Do not use"; break;
                case 0: text = "No"; break;
                case 1: text = "Yes"; break;
                case 2: text = "Use icon"; break;
        return text;

    public static Collection getMyOptionss() {
        Collection list = (Collection) new ArrayList();
        for (int i=-5; i<2; i++) {
          list.add(new LabelValueBean(
        return list;

Then in the ActionForm, a wrapper method can be used:

    public Collection getMyOptions() {
        return app.StaticClass.getMyOptions();

HTH - Ted