Ted

The <html:options> should look for a collection in the actionForm.
I have placed collections ArrayList for drop down selection in the
action form themselves. For example I have accessor / mutator
"ArrayList getCurrencyOptions()", and "setCurrencyOptions( ArrayList )".
[Those of us who work in finance know the usual bog standard
"USD", "EUR", "YEN",  "TWD" etc ] It is a bit silly to have
to use <bean:define> to get the collection from the ActionForm.
What I like about <html:options> is its verstatility it can work
any bean that returns a samentic option name and value.

the confusion is the naming of the tag attributes.

I suggest you have 4 attributes:

"collectionProperty" - defines the property name of the actionForm that
          returns a java.util.Collection. If the "name" attribute is supplied
          then that replaces the actionForm.

"bean"         - defines alternative bean to retrieve the collection other
          than the action form.

"name"         - if the collection comes from a named scope attribute rather
          than a bean

"labelAccessor"   - defines the name of the property that from the current
          collection retrieves the label.
               getOptionLabel() = > "optionLabel"

"valueAccessor "- defines the name of the property that from the current
          collection retrieves the value.
               getOptionValue() = > "optionValue"

--
Peter Pilgrim                 ++44 (0)207-545-9923
                                                      //_\\
"Mathematics is essentially the study of islands of  =======
disparate subjects in a sea of ignorance."           || ! ||
Andrew Wiles _____________


---------------------------------------- Message History 
----------------------------------------


From: Ted Husted <[EMAIL PROTECTED]> on 09/11/2001 14:11 EST

Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED]>

To:   Struts Users Mailing List <[EMAIL PROTECTED]>
cc:
Subject:  Re: AW: how do I use <html:options>


The propeties for options are very confusion, 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"/>

Then

<html:select property="image">
<html:options collection="myOptions" property="value"
labelProperty="label"/>
</html:select>
</td>

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(
              getMyOptions(i),
              String.valueOf(i)
          ));
        }
        return list;
    }

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


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

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/


> -----Ursprüngliche Nachricht-----
> Von: Scriven, Marcos [mailto:[EMAIL PROTECTED]]
> Gesendet: Donnerstag, 8. November 2001 21:23
> An: 'Struts Users Mailing List'
> Betreff: how do I use <html:options>
>
> I've just done a search on google for "option tag struts", and bizzarely the
> only thing I get back is about pro-wrestling?!
>
> I am stumped by the struts documentation on the <html:options> tag, for the
> collection property...
>
> "Name of the JSP bean (in some scope) which is itself a Collection of other
> beans, each of which has properties named by the "property" and
> "labelProperty" attributes that are used to retrieve the value and label for
> each option, respectively. [RT Expr] "
>
> Say I have a bean class called Currency, with methods getValue() and
> getName().
>
> In the options tag, I would have the following properties:
>
> property="value"
> labelProperty="name"
>
> but what should collection be? It says it should be a 'a bean which
> represents a collection'...
>
> I have set up a collection of beans like so in my form bean (just for
> testing, can easily go elsewhere)
>
> Collection currencies = new Vector();
> currencies.add(new Currency(0, "USD"));
> currencies.add(new Currency(1, "GBP"));
> currencies.add(new Currency(2, "EUR"));
> ...
> etc
>
> I've then tried putting in an accesor on my bean called getCurrencies()
>
> I'm very confused, please help
>
> Marcos

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>






--

This e-mail may contain confidential and/or privileged information. If you are not the 
intended recipient (or have received this e-mail in error) please notify the sender 
immediately and destroy this e-mail. Any unauthorized copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to