• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DynaActionForm does not retain the values submitted

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vili Leonardo
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic