You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kenny Smith <ke...@journalscape.com> on 2002/07/03 01:01:25 UTC

Use of

Hello,

I've having trouble figuring out how to use <html:select>.. I've read
through the struts docs, and I can see all of the available properties to
set, like which value I want selected, but it doesn't say how to set what
the list of options are. Am I just plain missing something?

Thanks,
Kenny Smith


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Use of

Posted by Joe Germuska <Jo...@Germuska.com>.
At 4:01 PM -0700 2002/07/02, Kenny Smith wrote:
>I've having trouble figuring out how to use <html:select>.. I've read
>through the struts docs, and I can see all of the available properties to
>set, like which value I want selected, but it doesn't say how to set what
>the list of options are. Am I just plain missing something?

Options go in the body of the <html:select> tag.  You can use one or 
more <html:option> tags, and/or one or more <html:options> tags.  If 
you're using Struts 1.1, you can use <html:optionsCollection>, which 
attempts to improve the syntax of the <html:options> tag.

All of those are discussed in the HTML taglib users guide.  It's true 
that the doc for <html:select> doesn't really discuss how you handle 
the actual options...  You may also want to consult the API doc for 
the taglib packages, which complements the user's guide. 
<http://jakarta.apache.org/struts/api/org/apache/struts/taglib/html/package-summary.html#package_description> 
It doesn't say a lot about options specifically, but it's worth 
checking out.

Joe

-- 
--
* Joe Germuska    { joe@germuska.com }
"It's pitiful, sometimes, if they've got it bad. Their eyes get 
glazed, they go white, their hands tremble.... As I watch them I 
often feel that a dope peddler is a gentleman compared with the man 
who sells records."
	--Sam Goody, 1956
tune in posse radio: <http://www.live365.com/stations/289268>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Use of

Posted by Joseph Barefoot <jo...@hereuare.com>.
oops, that should have read "..an option and/or options [plural] tag".  You
can also put multiple option tags. I'm not sure if you can use multiple
options (plural) tags though.

> -----Original Message-----
> From: Joseph Barefoot [mailto:josephb@hereuare.com]
> Sent: Tuesday, July 02, 2002 4:16 PM
> To: Struts Users Mailing List
> Subject: RE: Use of <html:select>
>
>
> Yep, the docs are a bit obtuse about the actual usage, aren't they? :)
>
> You put an option and/or option tag inside the select tag, like so:
>
> <bean:define id="myCollection" name="myFormBean"
> property="myCollectionField" scope="page" />
>
> <html:select name="myFormBean" property="myField">
>       <html:option value="-1">
>         Please choose something.
>       </html:option>
>       <html:options collection="myCollection" labelProperty="key"
> property="value" />
>  </html:select>
>
>
> Here, the option tag will ouput "Please choose something" as the label for
> the top option in the rendered html tags, with -1 as the value.
> The options
> tag points to a Collection object (or an array) in some scope containing a
> list of beans with getKey() and getValue() methods which return the value
> for the option label and the value for the option value, respectively.
>
> Note that in this example, I defined the Collection Object in page scope
> using a bean:define tag that references a form bean field, but it just as
> easily could have bean an Object already in session or request
> scope (placed
> there by an Action or something) named "myCollection".
>
>
> peace,
>
> Joe Barefoot
>
> > -----Original Message-----
> > From: Kenny Smith [mailto:kenny@journalscape.com]
> > Sent: Tuesday, July 02, 2002 4:01 PM
> > To: Struts User
> > Subject: Use of <html:select>
> >
> >
> > Hello,
> >
> > I've having trouble figuring out how to use <html:select>.. I've read
> > through the struts docs, and I can see all of the available
> properties to
> > set, like which value I want selected, but it doesn't say how
> to set what
> > the list of options are. Am I just plain missing something?
> >
> > Thanks,
> > Kenny Smith
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Use of

Posted by Joseph Barefoot <jo...@hereuare.com>.
Yep, the docs are a bit obtuse about the actual usage, aren't they? :)

You put an option and/or option tag inside the select tag, like so:

<bean:define id="myCollection" name="myFormBean"
property="myCollectionField" scope="page" />

<html:select name="myFormBean" property="myField">
      <html:option value="-1">
        Please choose something.
      </html:option>
      <html:options collection="myCollection" labelProperty="key"
property="value" />
 </html:select>


Here, the option tag will ouput "Please choose something" as the label for
the top option in the rendered html tags, with -1 as the value.  The options
tag points to a Collection object (or an array) in some scope containing a
list of beans with getKey() and getValue() methods which return the value
for the option label and the value for the option value, respectively.

Note that in this example, I defined the Collection Object in page scope
using a bean:define tag that references a form bean field, but it just as
easily could have bean an Object already in session or request scope (placed
there by an Action or something) named "myCollection".


peace,

Joe Barefoot

> -----Original Message-----
> From: Kenny Smith [mailto:kenny@journalscape.com]
> Sent: Tuesday, July 02, 2002 4:01 PM
> To: Struts User
> Subject: Use of <html:select>
>
>
> Hello,
>
> I've having trouble figuring out how to use <html:select>.. I've read
> through the struts docs, and I can see all of the available properties to
> set, like which value I want selected, but it doesn't say how to set what
> the list of options are. Am I just plain missing something?
>
> Thanks,
> Kenny Smith
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>