struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Shneyderman" <>
Subject RE: Populating select boxes dynamically
Date Tue, 01 Jul 2003 12:06:09 GMT

> What is the process to be followed? Can somebody give me links to
> examples on the net?

There are many different ways. From do it yourself to get your options
>From a collection that is a bean in one of the contexts. 

I will explain do it yourself method the others are similar with an
exception there are better ways to point to your collections.

Suppose you have a SystemDictionary object that has a bunch of static
listThisAndThat () methods that return collections. Now to turn this
Collection into options drop-down. 
You do the following in your JSP:
<% page.setAttribute ("myCountries", SystemDictionary.listCountries ());
<html:select name="country">
  <html:options collection="myCountries" property="countryId"
labelProperty="countryName" />

This will render a drop-down on your HTML that will have countries to 
Select from. Note Your SystemDictionary.listCountries () should return
A collection of Country objects that have at least two methods
getCountryId () and getCountryName (). Each of which will be called to
render your options as follows:
 <option value="<%= currentCountry.getCountryId ().toString () %>"><%=
currentCountry.getCountryName ().toString () %></option>

> Any information would be very helpful to me.

Just read <html:select>, <html:options> and <html:optionsCollection>
documentation. It is a bit confusing at first but if you take your time
to read it thru and play around with it, you going to save some time.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message