This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes DynaActionForm does not retain the values submitted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "DynaActionForm does not retain the values submitted " Watch "DynaActionForm does not retain the values submitted " New topic
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: 4727

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
 
Consider Paul's rocket mass heater.
 
subject: DynaActionForm does not retain the values submitted
 
Similar Threads
Problem of insert data into database
how to add data in request object and pass it to next page?
Recover ArrayForm in Action
Radio Select and Other
nested iterate with ArrayList