Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STRUTS: Iterating over a collection of ActionErrors

 
Philip Pomario
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I currently have a JavaBean that maintains a collection of Strut's ActionErrors objects, and another collection of Strings. There is absolutely no problem in using the iterate tag to retrieve the Strings and displaying them on the screen. The tough problem is retrieving the ActionErrors and showing them. The following is how I coded the JSP:

<logic:iterate name="catalogPublishedResults" property="notPublishedItems" type="com.mercador.ejb.session.GCIProduct.GCIItemErrors" id="notPublishedItemReference">

<bean:write name="notPublishedItemReference" property="GTIN" />,

<logic:iterate name="notPublishedItemReference" property="errors" type="org.apache.struts.action.ActionError" id="notPublishedItemReferenceErrors">
(<i><html:errors name="notPublishedItemReferenceErrors" /></i>
</logic:iterate>

</logic:iterate>

This is the error message I get from webLogic when accessing the page: javax.servlet.jsp.JspException: Cannot create iterator for this collection

Any help is much appreciated.

Regards,
Filipe Pomar
 
Sheldon Fernandes
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the method GCIItemErrors.getErrors() return a "Collection of ActionErrors objects" or a singe "ActionErrors" object?
Note the return type of the method should be one of the following (as expected by logic iterate tag):
- Iterator
- Collection
- Map (whose values are to be iterated over)
- array

If getErrors() directly returns you the "ActionErrors" object, then you do not need the inner iterate tag. In this case you might need to put your "ActionErrors" object in request scope so that the <html:errors> tag finds it.

Sheldon Fernandes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic