This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving form bean with Array of objects (collection)

 
sreekar na
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic