struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aparna Tula" <aparna.t...@SYNCHRONOSS.com>
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"
labelProperty="name"/>
</html:select>

- Aparna


-----Original Message-----
From: Shriver, Ryan [mailto:Ryan.Shriver@whitlockebs.com]
Sent: Wednesday, August 22, 2001 11:03 AM
To: 'struts-user@jakarta.apache.org'
Subject: Help with logic:iterate


Hello,
I have a Collection that I'd like to iterate over and display using
Struts.
I've been unsuccessful to this point and I'm in hopes someone can tell
me
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)iterator.next();
 %>
  <html:option value="<%= song.getStringId() %>">
    <%= song.getName() %>
  </html:option>
 <%
 } // while
 %>
</html:select>

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"/>
  </html:option>
 </logic:iterate>
</html:select>

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

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
is
loaded via a hyperlink that doesn't go through an Action.

Thanks in advance.

-ryan

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


Mime
View raw message