File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Saving form bean with Array of objects (collection) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Saving form bean with Array of objects (collection)" Watch "Saving form bean with Array of objects (collection)" New topic
Author

Saving form bean with Array of objects (collection)

sreekar na
Greenhorn

Joined: Aug 22, 2008
Posts: 3
Hi all, this is my first post here, if I am too long or missed some thing please let me know thanks.. I am facing problem to capture my array of objects(Order) in form bean into action class, the array i get from form is NULL.. Let me explain.

There are Two action classes, one action form and a JSP page.

1.DisplayAction.java (action class)- populates my form bean
2.SaveAction.java (action class)- jsp page below directs to this action.
3.OrderListForm.java (form bean)- contains an array of objects(Order.java)
Order.java (java bean)- value object implements Serializable.
4.Replacement.jsp (page)- page that displays my orders and captures data with checkbox.

DisplayAction.java class populate my form bean with array of Order(value object). I can see all the Order's listed on Replacement.jsp page. This page not only displays the Order's but also captures data from user.

Code for OrderListForm.java (form bean)
---------------------------------------
public class OrderListForm extends ActionForm {

protected org.frb.orders.Order[] orderList;

/** Creates a new instance of OrderListForm */
public OrderListForm() {
this.init();
}

// Struts Methods...
public void init() {
this.orderList = null;

}


public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);
this.init();
}


public org.frb.crt.orders.Order[] getOrderList() {
return orderList;
}


public void setOrderList(org.frb.orders.Order[] orderList) {

VPNOrder[] oList = new VPNOrder[orderList.length];
for(int i = 0; i < orderList.length; i++) {
VPNOrder vpnOrder = new VPNOrder();
vpnOrder = (VPNOrder)orderList[i];
oList[i] = vpnOrder;
}
this.orderList = oList;
}
}
---------------------------------------

Code for Order.java (array of this objects present in form bean)
----------------------------------------------------------------
public class Order implements Serializable {
private String orderName;
private boolean decommission;

public java.lang.String getOrderName() {
return orderName;
}

public void setOrderName(java.lang.String orderName) {
this.orderName = orderName;
}

public boolean getDecommission() {
return decommission;
}

public void setDecommission(boolean decommission) {
this.decommission = decommission;
}

}
----------------------------------------------------------------

Code for Replacement.jsp
------------------------
<bean:define id="form" name="orderListForm" type="org.frb.orders.web.OrderListForm" />

<logic:present name="form" property="orderList">
<logic:iterate id="VPNorder" type="org.frb.orders.Order" name="form" property="orderList" scope="session">
<TR>
<TD align="center"><html:checkbox name="VPNorder" property="decommission"/>Decommission</TD>

<TD align="center"><bean:write name="VPNorder" property="orderName" /></TD>
</TR>
</logic:iterate>
</logic:present>
<html:submit />

-----------------------------------
I can see the Order Name in jsp page so the form is populated. But when I click the checkbox and hit submit button. Control reaches my SaveAction.java. Here my form do not contains the array. When I do debug and see the form, the value of the array is NULL. So I am not able to capture what user selected. Is there any problem with my JSP page? Am I missing any thing?

I actually started of with ArrayList but I read in some forum that ArrayList is not supported by FormBeans so I started using Array.

Can any one please let me know what I am doing wrong?
Thanks,
Sreekar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving form bean with Array of objects (collection)