Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic:iterate & DTO Problem

 
Eibhlin Reid
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know if it is possible to use <bean:write tag on a collection of DTO objects, within a <logic:iterate tag?
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can use logic:iterator to iterate through the collection, then use bean:write to write out info from your DTOs:



or

 
Eibhlin Reid
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that, we are already using the first piece of code EXACTLY as you gave it:

<logic resent name="topicsList">
<logic:iterate id="topic" name="topicsList" scope="request" >
<bean:write name="topic" property="title"/>
</logic:iterate><br>
</logic resent>

However we are recieveing the following error:
org.apache.jasper.JasperException: Cannot find bean topic in any scope
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your collection probably contains a null value. If so, you'll have to insert another logic:present for topic inside of the iterate tag.

It wouldn't hurt to try out JSTL's c:forEach for your iterations. Once you try it, you probably won't go back to logic:iterate. Just a suggestion.
 
Eibhlin Reid
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your help, as it turned out we were missing a tag at the top of of the JSP!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic