This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Struts and the fly likes Not getting contents of formbean's collection... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Not getting contents of formbean Watch "Not getting contents of formbean New topic

Not getting contents of formbean's collection...

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186

I am developing web application using Struts1.1. Now following is my (formbean)file.
public class ViewcartForm extends ActionForm {
/** cartsessiondata property */
private CartSessionData[] cartdata=new CartSessionData[0];

public CartSessionData[] getCartdata() {
return cartdata;
public void setCartdata(CartSessionData[] cartdata) {
this.cartdata = cartdata;


& this is content of my Viewcart.jsp file:-
<logic:empty name="viewcartForm" property="cartdata">
<td colspan="5">Your Shopping Cart is Empty!!!</td>
<logic:notEmpty name="viewcartForm" property="cartdata">
<td colspan='25' class=header width="100%" height=30>
<center><blink>Parts in your Shopping Cart </blink></center>

<table border="1" cellpadding="0" width="100%" bgcolor="#71B8FF"
bordercolor="#000000" cellspacing="1">
<logic:iterate name="viewcartForm" property="cartdata"
<td colspan="2" class=darkodd>    Part ID:</td>
<td colspan="2" class=darkodd> <bean:write
name="partsincart" property="partid" /></td>
<td colspan="2" class=darkodd> <bean:write
name="partsincart" property="partdesc" /></td>

In The above jsp file I am not able to get any of the parts from my "cartsdata" collection inside my form bean.
What is problem here?
When I am executing viewcart.jsp file i am just getting the header inside <logic:notempty......> tag , i.e, I am just getting output "Parts in your Shopping Cart" on my jsp file. Rest I can't see. Whare I am wrong? PLease tell me.
Thanx in Advance.

********Deserve Before You Desire********
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I do not recall using the empty tags with arrays. Looking at the documentation, it just mentions null objects, empty strings and empty Collections. Since your class initializes your array, I am wondering if your array is actually empty but you get the notEmpty output because the array is not null.

If you are using and IDE with a debugger, you can try setting a breakpoint on the getCartdata method to see what it is returning.

- Brent
subject: Not getting contents of formbean's collection...
It's not a secret anymore!