You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Martin J. La Jeunesse" <mj...@pacbell.net> on 2001/02/27 02:42:39 UTC

Struggling with select/options

The examples I've seen using <html:options name="someBean"
property="someProperty" /> all seem to reference a collection defined in the
same jsp as the options tag. Could someone provide a rookie with an example
where the collection bean is not defined in the same jsp, but rather by, say
an action servlet or an application bean? For example, say I've got a User
bean with a Vector of ints called Accounts. I'd like to display those
accounts in a list-box - ultimately I'd like to display an associated name
and use the int as the option value. I know that I can use labelName and
labelProperty for this, but I haven't gotten the first part working yet.
I'm able to get <html:options collection= working, but I'm stumped on the
other options mode. Most of the ways I've tried it result in class cast
exceptions during the jsp compile.
thank you,
Marty La Jeunesse




Re: Struggling with select/options

Posted by Eric Rasmussen <er...@websidestory.com>.
<html:options collection="temp_collection" property="id"
labelProperty="name"/>

where 'temp_collection' is the type of class referenced by the 'name'
attribute of the html:select, 'id' is the value returned by the getId()
method (to be entered into the 'value' field of the option), and 'name' is
the value returned by the getName() method (to be the text dispayed by the
option).

So, if your collection (added to the request object by the controller class)
is of type com.whatever.TestClass objects, and TestClass has the methods
getId() and getName(), the following jsp code would (should) produce the
following html code:
    jsp code:
        <bean:define id="test" name="test" type="com.whatever.TestClass"/>

        [text label:]
        <html:select property="testclassid" name="test">
            <html:options collection="temp_collection" property="id"
labelProperty="name"/>
        </html:select>

    html code:
        [text label:]
        <select name="testclassd">
            <option value="[id of first TestClass object]">[name of first
TestClass object]</option>
            [ ... ]
            <option value="[id if last TestClass object]">[name of last
TestClass object]</option>
        </select>

    Hope this helps,
        - eric

----- Original Message -----
From: "Martin J. La Jeunesse" <mj...@pacbell.net>
To: <st...@jakarta.apache.org>
Sent: Monday, February 26, 2001 5:42 PM
Subject: Struggling with select/options


> The examples I've seen using <html:options name="someBean"
> property="someProperty" /> all seem to reference a collection defined in
the
> same jsp as the options tag. Could someone provide a rookie with an
example
> where the collection bean is not defined in the same jsp, but rather by,
say
> an action servlet or an application bean? For example, say I've got a User
> bean with a Vector of ints called Accounts. I'd like to display those
> accounts in a list-box - ultimately I'd like to display an associated name
> and use the int as the option value. I know that I can use labelName and
> labelProperty for this, but I haven't gotten the first part working yet.
> I'm able to get <html:options collection= working, but I'm stumped on the
> other options mode. Most of the ways I've tried it result in class cast
> exceptions during the jsp compile.
> thank you,
> Marty La Jeunesse
>
>
>
>