You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shamdasani Nimmi-ANS004 <AN...@NAmerica.mot.com> on 2000/08/10 02:49:38 UTC

Is there a way to have 'None Selected' item in 'options' tag

Hi,

How would I add a 'None Selected' item in my combo-box using 'options' tag?

Also whenever the key/value properties for this combo-box are empty I would
like to show 'None Selected' item.

Thanks.
 
-Nimmi


Re: Is there a way to have 'None Selected' item in 'options' tag

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Shamdasani Nimmi-ANS004 wrote:

> Hi,
>
> How would I add a 'None Selected' item in my combo-box using 'options' tag?
>
> Also whenever the key/value properties for this combo-box are empty I would
> like to show 'None Selected' item.
>

I would normally handle this by having a <struts:option> tag for the "None
Selected" option in addition to a <struts:options> tag for all the legal
values.  If you put the "None Selected" one first, that will be the value
displayed if no other option is explicitly requested.

<struts:select property="abc">
    <struts:option value="-1">None Selected</struts:option>
    <struts:options ... />
</struts:select>

As a side effect of doing this, the form is actually going to submit a value
for this field if the "None Selected" option is not changed.  You will want to
pick a "value" submitted for this purpose that your bean will recognize as an
indicator that no other real option was chosen.  For example, if your values
are usually non-negative integers, you might use "-1" as the value sent by the
"None Selected" option.

>
> Thanks.
>
> -Nimmi

Craig