You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Simon Liang <Sl...@verticalnet.com> on 2001/06/20 01:18:55 UTC

Options tag

Hi All:

I don't know if i am doing something wrong or not. Either i am really stupid
or i am totally misunderstanding something here - as i have tried for the
last serveral hrs getting options tag to output the 'selected' text in html.

I basically followed the example(subscription.jsp) on this, but couldn't
figure out why it's not outputting 'selected' as the example claims is
working.

<!-----------------------------------------------here is the jsp --> 
<%
  java.util.ArrayList list = new java.util.ArrayList();
  list.add(new com.vns.um.struts.LabelValueBean("English", "en_us"));
  list.add(new com.vns.um.struts.LabelValueBean("British English",
"en_uk"));
  pageContext.setAttribute("languageTypes", list);
%>

<html:form action="/saveProfile"> 
<HR>
  <TR>
    <td><html:text name="userprofileForm" property="uid" size="10"
maxlength="10"/></TD>
    <td><html:text name="userprofileForm" property="password" size="10"
maxlength="10"/></TD>
    <td><html:text name="userprofileForm" property="firstName" size="10"
maxlength="10"/></TD>
  </tr> 
   <tr>
  <html:select name="userprofileForm" property="preferredLanguage" >
            <html:options collection="languageTypes" property="value"
match="en_uk"
                   labelProperty="label"/>
  </html:select> 
  </tr>
</html:form> 

How do i get "en_uk" selected????? Thanks for any help.

Simon




============================================================================
This message is intended only for the use of the Addressee(s) and may
contain information that is PRIVILEGED and CONFIDENTIAL. If you are not
the intended recipient, dissemination of this communication is prohibited.
If you have received this communication in error, please erase all copies
of the message and its attachments and notify postmaster@verticalnet.com
immediately.
============================================================================


Re: Options tag

Posted by Philip Planinsky <ph...@skalasoft.com>.
Hi Simon,

suppose you have the following
labels in options:

green
yellow
red

and the corresponding values:

1
2
3

All you have to do is:

                <html:select property="color">
                        <html:options collection="allcolors" property="id"
propertyLabel="name"/>
                </html:select>

where 'color' is an: private int color;
in your ActionForm bean

and 'allcolors' is a collection of beans

so if you want the 'yellow' to be preselected you just set the
'color' property of your form to value 2 before displaying the JSP.

regards,
Philip


----- Original Message -----
From: "Simon Liang" <Sl...@verticalnet.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, June 20, 2001 2:18 AM
Subject: Options tag


> Hi All:
>
> I don't know if i am doing something wrong or not. Either i am really
stupid
> or i am totally misunderstanding something here - as i have tried for the
> last serveral hrs getting options tag to output the 'selected' text in
html.
>
> I basically followed the example(subscription.jsp) on this, but couldn't
> figure out why it's not outputting 'selected' as the example claims is
> working.
>
> <!-----------------------------------------------here is the jsp -->
> <%
>   java.util.ArrayList list = new java.util.ArrayList();
>   list.add(new com.vns.um.struts.LabelValueBean("English", "en_us"));
>   list.add(new com.vns.um.struts.LabelValueBean("British English",
> "en_uk"));
>   pageContext.setAttribute("languageTypes", list);
> %>
>
> <html:form action="/saveProfile">
> <HR>
>   <TR>
>     <td><html:text name="userprofileForm" property="uid" size="10"
> maxlength="10"/></TD>
>     <td><html:text name="userprofileForm" property="password" size="10"
> maxlength="10"/></TD>
>     <td><html:text name="userprofileForm" property="firstName" size="10"
> maxlength="10"/></TD>
>   </tr>
>    <tr>
>   <html:select name="userprofileForm" property="preferredLanguage" >
>             <html:options collection="languageTypes" property="value"
> match="en_uk"
>                    labelProperty="label"/>
>   </html:select>
>   </tr>
> </html:form>
>
> How do i get "en_uk" selected????? Thanks for any help.
>
> Simon
>
>
>
>
>
============================================================================
> This message is intended only for the use of the Addressee(s) and may
> contain information that is PRIVILEGED and CONFIDENTIAL. If you are not
> the intended recipient, dissemination of this communication is prohibited.
> If you have received this communication in error, please erase all copies
> of the message and its attachments and notify postmaster@verticalnet.com
> immediately.
>
============================================================================
>