File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes ArrayList in <HTML:SELECT> tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ArrayList in <HTML:SELECT> tag" Watch "ArrayList in <HTML:SELECT> tag" New topic

ArrayList in <HTML:SELECT> tag

Vijay jai Singh

Joined: Jan 07, 2009
Posts: 26
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
Praveen Sangolli

Joined: May 22, 2008
Posts: 28
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>


Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.

Consultant, Sima Solutions
I agree. Here's the link:
subject: ArrayList in <HTML:SELECT> tag
It's not a secret anymore!