You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Matthew Hegarty <ma...@morse.com> on 2004/04/23 15:13:50 UTC

html:select - can't display default option

Hi all

I am using <html:select>, and trying to get the drop-down to default to a Boolean value in a bean, ie true, false, or blank if the bean is null.
My bean (MyBean) contains the method getMyValue() which returns a Boolean object.

In the code snippet below, the c:out statement confirms that the value of the property is 'true'.  I expect that the 'true' option will be pre-selected (which it is if you add "value='true'" to html:select), but doing this dynamically with the c:out tag doesn't work - the blank value is always the
one pre-selected.

Can someone suggest anything I am doing wrong, or suggest a better approach (i'm relatively new to Struts).

            <c:out value='${MyBean.myValue}' /><br>
            <html:select name="MyBean" property="myValue" value="<c:out value='${MyBean.myValue}' />">
                <html:option value="" key="jsp.form.booleandropdown.default" bundle="JSP_LABELS" />
                <html:option value="true" key="jsp.form.booleandropdown.true" bundle="JSP_LABELS" />
                <html:option value="false" key="jsp.form.booleandropdown.false" bundle="JSP_LABELS" />
            </html:select>

Thanks
Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: html:select - can't display default option

Posted by "Victor R. Cardona" <vc...@covad.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Matthew Hegarty wrote:
| Hi all
|
| I am using <html:select>, and trying to get the drop-down to default
to a Boolean value in a bean, ie true, false, or blank if the bean is null.
| My bean (MyBean) contains the method getMyValue() which returns a
Boolean object.
|
| In the code snippet below, the c:out statement confirms that the value
of the property is 'true'.  I expect that the 'true' option will be
pre-selected (which it is if you add "value='true'" to html:select), but
doing this dynamically with the c:out tag doesn't work - the blank value
is always the
| one pre-selected.
|
| Can someone suggest anything I am doing wrong, or suggest a better
approach (i'm relatively new to Struts).
|
|             <c:out value='${MyBean.myValue}' /><br>
|             <html:select name="MyBean" property="myValue"
value="<c:out value='${MyBean.myValue}' />">
|                 <html:option value=""
key="jsp.form.booleandropdown.default" bundle="JSP_LABELS" />
|                 <html:option value="true"
key="jsp.form.booleandropdown.true" bundle="JSP_LABELS" />
|                 <html:option value="false"
key="jsp.form.booleandropdown.false" bundle="JSP_LABELS" />
|             </html:select>

This is just a guess, but you could try writing it like this:
<html:select name="MyBean" property="myValue" value="${Mybean.myValue}">
	...
</html:select>

I think the problem is the c:out tag in the value attribute. In any
case, you don't need it. You can use EL expressions anywhere if you are
using a container that supports the JSP2.0 specs.

HTH,
Victor
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAiSVC8MW+BaXrmuERAtoRAJ4mYhJQUnzUeU6FVIkdHaWPLUaIyACeL4sk
uZyNMxCBOt/0QnSq9nVwJNo=
=9qXm
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org