• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList in <HTML:SELECT> tag

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Struts 1.2. I have one ArrayList and one HashMap in my form bean. Name of these collection are myList and myMap. Form bean name is myForm and scope is request.

I would like to know how to display values from arraylist and hashmap to <html:select> tag for creating drop down list.

Thank you for your help
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vijay, you can try using <logic> tag to display the contents from your List..

Let me type in some sample code for you..
Make sure you place your list in a session or request scope for the iterator to access it...

<html:select name="select">

<logic:iterate id="lis" name="mylist" indexId="i">

<option value='${i+1}'><bean:write name="lis" property="category" /></option>

</logic:iterate>

</html:select>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's an easier way to do this using the html:optionsCollection tag. Below is an example using both a list and a map.

List example:

The above assumes that myList is a list of JavaBeans, each having a propertyUsedForLabel and a propertyUsedForValue property.

Map Example:

The above assumes the key of each map entry is the code you want sent to the server if the option is selected and the value of the map entry is the label you want displayed for the option.
 
Your mind is under my control .... your will is now mine .... read this tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic