| Author |
DynaActionForm does not retain the values submitted
|
Vili Leonardo
Greenhorn
Joined: Mar 12, 2004
Posts: 18
|
|
Hi, I have an array of QuoteItem object stored in a DynaActionForm. The QuoteItem is a bean with the following setter and getter for these properties: partID, partDesc, partUOM and partQty. This is a definition of the DynaActionForm <form-bean name="QuoteItemForm" type="org.apache.struts.action.DynaActionForm"> <form-property name="quote" type="com.leonardo.oms.QuoteItem[]"></form-property> </form-bean> The rendered html looks like this: <form name="QuoteItemForm" method="post" action="/coco/processQuoteItem.do?display=true"> PartID: PA123 : art 123 : C</br> Part Qty: <input type="text" name="lineItem[0].partQty" value=""></br> PartID: PA234 : art 234 : C</br> Part Qty: <input type="text" name="lineItem[1].partQty" value=""></br> PartID: PA456 : art 456 : C</br> Part Qty: <input type="text" name="lineItem[2].partQty" value=""></br> <input type="submit" value="Create Quote"> </form> I entered the qty values and submit the form, the ProcessQuoteItem.action that processes the form is: public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { //Get the form DynaActionForm df = (DynaActionForm) form; ArrayList arrListQuote = new ArrayList(); //Create session object HttpSession session = request.getSession(); //get the QuoteItem array QuoteItem[] lineItem = (QuoteItem[]) df.get("quote"); for(int i=0; i<lineItem.length; i++ ){ if(lineItem[i].getPartQty() != null){ arrListQuote.add(lineItem[i]); System.out.println(lineItem[i].getPartQty()); }else{ System.out.println(lineItem[i].getPartQty()); } } session.setAttribute("arrListQuote", arrListQuote); return (mapping.findForward("success")); } The problem is lineItem[i].getpartQty() does not retain the qty values that are submitted with the form. The system.out shows blanks. Where do I go wrong? Any tips or hints... TIA -Vili
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4695
|
|
I don't think I've ever seen an ActionForward coded out before, so I'll assume you know what you're doing with that one. I do recommend using: HttpSession session = request.getSession(false); as this will prevent many possible debug frustrations.
|
A good workman is known by his tools.
|
 |
Vili Leonardo
Greenhorn
Joined: Mar 12, 2004
Posts: 18
|
|
Hi, Basically, I want to build a dynamically sized form. I follow an approach outlined in this article. http://www.developer.com/java/ejb/article.php/3321521 Is this the right way of creating dynamic sized form? Thanks -Vili
|
 |
 |
|
|
subject: DynaActionForm does not retain the values submitted
|
|
|