You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stanley Tan <st...@crosswinds.net> on 2001/04/15 07:56:42 UTC
Iterate Tag
Hi,
I have an iterate tag that loops through the items in a shopping
cart. Now, everything is working fine UNLESS I view the page when the
shopping cart is empty.
<logic:iterate id="shoppingcartitem" name="cart" property="products">
<tr bgcolor="<jsp:getProperty name="color" property="next"/>">
<td><bean:write name="shoppingcartitem"
property="product.productID"/></td>
<td><bean:write name="shoppingcartitem"
property="product.productName"/></td>
<td align="center"><bean:write name="shoppingcartitem"
property="quantity"/></td>
<td align="center"><bean:write name="shoppingcartitem"
property="product.productPrice"/></td>
</tr>
</logic:iterate>
When it is empty, I get
javax.servlet.jsp.JspException: Cannot create iterator for bean cart and
property cart at
org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:317)
at _jsp._stan1._viewcart__jsp._jspService(/stan1/viewcart.jsp:50)
What can I do? Any suggestions?
Thanks in advance,
Stanley
Re: Iterate Tag
Posted by Tharwat Abdul-Malik <ta...@grandtalent.com>.
What if you add a size property, then put a logic greaterThan (zero) tag
around the iterate tag.
----- Original Message -----
From: "Stanley Tan" <st...@crosswinds.net>
To: <st...@jakarta.apache.org>
Sent: Sunday, April 15, 2001 1:56 AM
Subject: Iterate Tag
> Hi,
>
> I have an iterate tag that loops through the items in a shopping
> cart. Now, everything is working fine UNLESS I view the page when the
> shopping cart is empty.
>
> <logic:iterate id="shoppingcartitem" name="cart" property="products">
> <tr bgcolor="<jsp:getProperty name="color" property="next"/>">
> <td><bean:write name="shoppingcartitem"
> property="product.productID"/></td>
> <td><bean:write name="shoppingcartitem"
> property="product.productName"/></td>
> <td align="center"><bean:write name="shoppingcartitem"
> property="quantity"/></td>
> <td align="center"><bean:write name="shoppingcartitem"
> property="product.productPrice"/></td>
> </tr>
> </logic:iterate>
>
> When it is empty, I get
>
> javax.servlet.jsp.JspException: Cannot create iterator for bean cart and
> property cart at
> org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:317)
> at _jsp._stan1._viewcart__jsp._jspService(/stan1/viewcart.jsp:50)
>
> What can I do? Any suggestions?
>
> Thanks in advance,
>
> Stanley
>
>
Re: Iterate Tag
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Sun, 15 Apr 2001, Stanley Tan wrote:
> Hi,
>
> I have an iterate tag that loops through the items in a shopping
> cart. Now, everything is working fine UNLESS I view the page when the
> shopping cart is empty.
>
> <logic:iterate id="shoppingcartitem" name="cart" property="products">
> <tr bgcolor="<jsp:getProperty name="color" property="next"/>">
> <td><bean:write name="shoppingcartitem"
> property="product.productID"/></td>
> <td><bean:write name="shoppingcartitem"
> property="product.productName"/></td>
> <td align="center"><bean:write name="shoppingcartitem"
> property="quantity"/></td>
> <td align="center"><bean:write name="shoppingcartitem"
> property="product.productPrice"/></td>
> </tr>
> </logic:iterate>
>
> When it is empty, I get
>
> javax.servlet.jsp.JspException: Cannot create iterator for bean cart and
> property cart at
> org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:317)
> at _jsp._stan1._viewcart__jsp._jspService(/stan1/viewcart.jsp:50)
>
> What can I do? Any suggestions?
>
> Thanks in advance,
>
> Stanley
>
>
What does your getProducts() method return when the shopping cart is
empty? You'll have a problem like this if you return null -- try
returning a zero-length array (or an empty List, or whatever) instead.
You can also use the <bean:size> method to retrieve the number of elements
in a collection or array, and then use that in a <logic:xxx> statement to
display the loop only if there is at least one item.
Craig