You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Larry Maturo <lm...@athensgroup.com> on 2002/01/10 22:31:45 UTC

select/options/option

Since I see these questions come up, and I just got them
figured out, I thought I would share them with the mailing
list.

Select can be used with:

a: A collection of strings, such as an arraylist
b: A collection of beans, each of which has string fields
c: Hard coded values

I know you can combine a and c, as well as b and c.  I'm
guessing you could combine a, b, and c as well.

With An ArrayList of Strings
----------------------------

ArrayList name is nameList.  This list has been put into 
either the request or session.

name of field in form bean to set is selectedValue.

<html:select property="selectedValue">
	<html:options name="nameList" />
</html:select>

With An ArrayList of Beans
--------------------------

Bean string fields of interest are:
  1.  displayValue
  2.  idValue

ArrayList name is beanList.  This list has been put into 
either the request or session.

name of field in form bean to set is selectedValue.  It
should be set to the idValue of the selected bean.

<html:select property="selectedValue">
	<html:options collection="nameList" property="idValue" 
	
labelProperty="displayValue"/>
</html:select>

With HardCoded Values
---------------------

name of field in form bean to set is selectedValue.
<html:select property="selectedValue">
	<html:option value="value_1"/>
	<html:option value="value_2"/>	
	<html:option value="value_3"/>
</html:select>

-- Larry Maturo
   lmaturo@athensgroup.com
   Athens Group, Inc.

Re: select/options/option

Posted by Manuel Martin <li...@martinnet.de>.
Hello,

On Fri, 11 Jan 2002 15:48:31 -0800 
Jason Wells <jw...@xsilogy.com> wrote:
> Using the <html:option> tag, is there a way to set an option to be 
> initially selected? I'm looking for something equivalent to
> 
> <option value="blah" selected>blah</option>
> 
> I don't see mention of this in the online docs for the HTML taglib.

This can be done by initializing the form-bean with the value you'd like
to be selected by default. Very nice indeed.

Bye, MM
-- 
http://www.martinnet.de


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


Re: select/options/option

Posted by Arron <ar...@pacific.net.au>.
The value which is returned from the "property" property in the select 
tag will make the choice for you if one of the choices matches this value.

eg.
Use the options tag running off a list, and if the property which is 
specified in the select tag matches one, Struts will select it for you.


Arron.

Jason Wells wrote:

> Thanks for the summarized info.
>
> Using the <html:option> tag, is there a way to set an option to be 
> initially selected? I'm looking for something equivalent to
>
> <option value="blah" selected>blah</option>
>
> I don't see mention of this in the online docs for the HTML taglib.
>
> Thanks,
> Jason
>
>
> Larry Maturo wrote:
>
>> Since I see these questions come up, and I just got them
>> figured out, I thought I would share them with the mailing
>> list.
>>
>> Select can be used with:
>>
>> a: A collection of strings, such as an arraylist
>> b: A collection of beans, each of which has string fields
>> c: Hard coded values
>>
>> I know you can combine a and c, as well as b and c.  I'm
>> guessing you could combine a, b, and c as well.
>>
>> With An ArrayList of Strings
>> ----------------------------
>>
>> ArrayList name is nameList.  This list has been put into either the 
>> request or session.
>>
>> name of field in form bean to set is selectedValue.
>>
>> <html:select property="selectedValue">
>>     <html:options name="nameList" />
>> </html:select>
>>
>> With An ArrayList of Beans
>> --------------------------
>>
>> Bean string fields of interest are:
>>   1.  displayValue
>>   2.  idValue
>>
>> ArrayList name is beanList.  This list has been put into either the 
>> request or session.
>>
>> name of field in form bean to set is selectedValue.  It
>> should be set to the idValue of the selected bean.
>>
>> <html:select property="selectedValue">
>>     <html:options collection="nameList" property="idValue"     
>> labelProperty="displayValue"/>
>> </html:select>
>>
>> With HardCoded Values
>> ---------------------
>>
>> name of field in form bean to set is selectedValue.
>> <html:select property="selectedValue">
>>     <html:option value="value_1"/>
>>     <html:option value="value_2"/>   
>>     <html:option value="value_3"/>
>> </html:select>
>>
>> -- Larry Maturo
>>    lmaturo@athensgroup.com
>>    Athens Group, Inc.
>
>



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


Re: select/options/option

Posted by Jason Wells <jw...@xsilogy.com>.
Thanks for the summarized info.

Using the <html:option> tag, is there a way to set an option to be 
initially selected? I'm looking for something equivalent to

<option value="blah" selected>blah</option>

I don't see mention of this in the online docs for the HTML taglib.

Thanks,
Jason


Larry Maturo wrote:

> Since I see these questions come up, and I just got them
> figured out, I thought I would share them with the mailing
> list.
> 
> Select can be used with:
> 
> a: A collection of strings, such as an arraylist
> b: A collection of beans, each of which has string fields
> c: Hard coded values
> 
> I know you can combine a and c, as well as b and c.  I'm
> guessing you could combine a, b, and c as well.
> 
> With An ArrayList of Strings
> ----------------------------
> 
> ArrayList name is nameList.  This list has been put into 
> either the request or session.
> 
> name of field in form bean to set is selectedValue.
> 
> <html:select property="selectedValue">
> 	<html:options name="nameList" />
> </html:select>
> 
> With An ArrayList of Beans
> --------------------------
> 
> Bean string fields of interest are:
>   1.  displayValue
>   2.  idValue
> 
> ArrayList name is beanList.  This list has been put into 
> either the request or session.
> 
> name of field in form bean to set is selectedValue.  It
> should be set to the idValue of the selected bean.
> 
> <html:select property="selectedValue">
> 	<html:options collection="nameList" property="idValue" 
> 	
> labelProperty="displayValue"/>
> </html:select>
> 
> With HardCoded Values
> ---------------------
> 
> name of field in form bean to set is selectedValue.
> <html:select property="selectedValue">
> 	<html:option value="value_1"/>
> 	<html:option value="value_2"/>	
> 	<html:option value="value_3"/>
> </html:select>
> 
> -- Larry Maturo
>    lmaturo@athensgroup.com
>    Athens Group, Inc.

-- 
Jason Wells
Web Architect
Xsilogy, Inc.
http://www.xsilogy.com/


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