File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ArrayList in <HTML:SELECT> tag" Watch "ArrayList in <HTML:SELECT> tag" New topic
Author

ArrayList in <HTML:SELECT> tag

Vijay jai Singh
Greenhorn

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
Greenhorn

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>

</logic:iterate>

</html:select>
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.


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList in <HTML:SELECT> tag