struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sudipta Sarkar" <sudiptasar...@hotmail.com>
Subject Re: How do I pre-select an element from a select list?
Date Thu, 21 Mar 2002 22:47:42 GMT
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) <struts@basebeans.com>
>Reply-To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>To: struts-user@jakarta.apache.org
>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" <danzig@avaya.com>
>  ===
>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
>danzig@avaya.com
>
>
>
>--
>To unsubscribe, e-mail:   
><mailto:struts-user-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: 
><mailto:struts-user-help@jakarta.apache.org>
>




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


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


Mime
View raw message