Step 1.
  In JSP
  <html:select property="choice" value="2" >
       <html:options labelProperty="labels" property="values"/>
  </html:select>

Step 2.
  the formbean has methods getLabels and getValues()

  public Collection getLabels()
        {
                ArrayList a = new ArrayList();
                a.add("One");
                a.add("Two");
                a.add("Three");
                return a;
        }

        public Collection getValues()
        {
                ArrayList a = new ArrayList();
                a.add("1");
                a.add("2");
                a.add("3");
                return a;
        }

Step 3.
  Notice the value attribute of <html:select> .This is the value to compare 
with for marking an option selected. Since I have specified value="2" so 
option "Two" will be selected.

Thanks
Sudipta

>From: Struts Newsgroup (@Basebeans.com) <[EMAIL PROTECTED]>
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: How do I pre-select an element from a select list?
>Date: Thu, 21 Mar 2002 13:55:02 -0800
>
>Subject: How do I pre-select an element from a select list?
>From: "Scott Danzig" <[EMAIL PROTECTED]>
>  ===
>Hi,
>
>Using Struts, I'm able to create an instance of a form, and prepopulate it
>with various information, then have it display this information in HTML
>spawned from a JSP page after the forward("success").  I'm unable, however,
>to figure out how to pre-select an element from a select list.  Like if a
>dropdown html SELECT menu displayed "First", "Second", and "Third", I'd 
>want
>to be able to have the form displayed with "Second" already selected.  
>Given
>I'm rather new to struts, let alone EJB and servlets, could someone please
>explain very clearly about how to do the three steps involved with this?
>First, adding the get/set functions to the form class.. what arguments 
>would
>they take?  Second, how to add the html:select and html:options tags to the
>JSP page so that I can prefill them with this form class, and lastly, in 
>the
>Action class which I have querying another datasource and retrieving this
>information, setting the necessary things in the form class, what
>property/attribute do I set in this form object, to have it preselect an
>element in the select list?  Thanks.
>
>Scott Danzig
>[EMAIL PROTECTED]
>
>
>
>--
>To unsubscribe, e-mail:   
><mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: 
><mailto:[EMAIL PROTECTED]>
>




_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


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

Reply via email to