struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aparna Tula" <>
Subject RE: Help with logic:iterate
Date Wed, 22 Aug 2001 15:21:19 GMT
If you use the <html:options> tag, it should be pretty simple. Since you
already have a collection of "songs" with each "song" having properties
for the label and value, you should be able to use this.

<% Collection songs = SongCache.getInstance().fetchAll(); %>
<html:select property="id">
  <html:options collection="songs" property="stringId"

- Aparna

-----Original Message-----
From: Shriver, Ryan []
Sent: Wednesday, August 22, 2001 11:03 AM
To: ''
Subject: Help with logic:iterate

I have a Collection that I'd like to iterate over and display using
I've been unsuccessful to this point and I'm in hopes someone can tell
what's wrong.

This works for populating a select list with values from the collection:

<% Collection songs = SongCache.getInstance().fetchAll(); %>
<html:select property="id">
 Iterator iterator = songs.iterator();
 while (iterator.hasNext()) {
   Song song = (Song);
  <html:option value="<%= song.getStringId() %>">
    <%= song.getName() %>
 } // while

This is what I'm trying and does not work. Any clues?

<% Collection songs = SongCache.getInstance().fetchAll(); %>
<html:select property="id">
 <logic:iterate id="element" name="songs" type="com.mycompany.Song">
  <html:option value="<bean:write name="element" property="stringId"/>">
    <bean:write name="element" property="name"/>

I get the error:
org.apache.jasper.compiler.ParseException: Attribute element has no

Also, does anyone know how to convert:
  <% Collection songs = SongCache.getInstance().fetchAll(); %>
into a <bean:define>? After reading the documentation it doesn't seem
possible. songs can't be set with request.setAttribute() b/c this page
loaded via a hyperlink that doesn't go through an Action.

Thanks in advance.


PS. Struts 1.0 on JBoss 2.2.2 w/embedded Tomcat 3.2.2

View raw message