File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes STRUTS: Iterating over a collection of ActionErrors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "STRUTS: Iterating over a collection of ActionErrors" Watch "STRUTS: Iterating over a collection of ActionErrors" New topic

STRUTS: Iterating over a collection of ActionErrors

Philip Pomario
Ranch Hand

Joined: Oct 03, 2003
Posts: 113
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>


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.

Filipe Pomar
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
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
I agree. Here's the link:
subject: STRUTS: Iterating over a collection of ActionErrors
It's not a secret anymore!