Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList in <HTML:SELECT> tag

 
Vijay jai Singh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
 
Praveen Sangolli
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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>
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic