You specify a collection just like any other property in the form bean--with a get/set 
pair.  You should create a tuple bean to hold your label/value pairs, call it 
OptionBean, KeyValueBean, or whatever, and your Collection will be a collection of 
these beans, populated with the label/value pairs you wish to use in <html:options>.  
I believe you can actually use an array of your OptionBeans for <html:options> instead 
of a Collection object if you like...usually I stick with ArrayList though (my fav. 
Collection).  Just populate the collection and set in the form before forwarding to 
your JSP.

For the JSP tags at the bottom, you'd want these methods in your objects: 

// *** MyFormBean:

// Collection of OptionBean objects
getMyCollection()
setMyCollection(Collection c)

// Holds the value selected from the drop-down
getSelectedValue()
setSelectedValue(String s)


// *** OptionBean:

getMyValueField()
setMyValueField(String s)
getMyLabelField()
setMyLabelField(String s)



// *** JSP:

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

<html:select property="selectedValue" >
        <html:options collection="myCollection" property="myValueField" 
labelProperty="myLabelField" />
</html:select> 


peace,
joe




> -----Original Message-----
> From: Chris _ [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, September 03, 2002 7:52 PM
> To: [EMAIL PROTECTED]
> Subject: RE: <html:options collection...> question
> 
> 
> Thanks Joe,
> 
> Just for clarities' sake, how exactly would I go about specifying the 
> collection in the form bean?
> 
> Does anyone know of any code examples that I could look at?
> 
> 
>  > hi all.  I am somewhat new to struts and have a question
>  > regarding the
>  > <html:options> tag.
> 
> hi. :)
> 
>  >
>  > If I wanted to specify the collection to come from an array or list
>  > contained in a bean, how would that be accomplished?
>  >
>  > can I just import the bean class into the jsp and then use
>  > <html:options
>  > collection=[name of property]>?
> 
> If my collection is in my form bean, this is how I would do 
> it in the JSP:
> 
> <bean:define id="myCollection" name="myFormBean" 
> property="myCollectionField" />
> 
> <html:options collection="myCollection" property="myValueField" 
> labelProperty="myLabelField" />
> 
>  >
>  > also...if say I wanted to put this information in a utility
>  > class to make it
>  > available to a number of different jsp's, how would I tell
>  > the tag to use
>  > bean X instead of the FormBean associated with the page in
>  > the config file?
> 
> If bean X is already instantiated and in the request/session, 
> then all you 
> would have to do is change your <bean:define> tag to 
> reference the attribute 
> name of bean X:
> 
> // do this in your action somewhere
> request.setAttribute("beanX", new BeanX() );
> 
> // and this in your JSP
> <bean:define id="myCollection" name="beanX" 
> property="myGlobalCollection" />
> 
> 
> Note that if this utility bean is global to the web app., 
> then you probably 
> want to put the bean into the ServletContext, so that it's 
> only created 
> once.  Then you would fetch it from the ServletContext in 
> your action and 
> stuff it into the request so it can be accessed from your JSPs.
> 
>  >
>  > I'm sorry if this is a dumb question, but I have searched the
>  > archives and
>  > found nothing.
> 
> Not a dumb question.  The docs for <html:options> are difficult to 
> understand, and the semantics for the tag's attributes are completely 
> non-intuitive.
> 
>  >
>  > Thanks in advance for your assistance.  It is much appreciated.
>  >
>  > Regards,
>  >
>  > Chris
>  >
>  > _________________________________________________________________
>  > Send and receive Hotmail on your mobile device: 
http://mobile.msn.com
 >
 >
 > --
 > To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: 
<mailto:[EMAIL PROTECTED]>


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





_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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


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

Reply via email to