On 21 Nov 2003, at 17:18, Yee, Richard K,,DMDCWEST wrote:


Matt,
The answer to your main question is, "No". You don't have to specify the
form as the input of the preloader. You don't even really have to have a
separate 'pre-loader' action for this form. In any action that will forward
to your JSP page that displays your form, you can create a new form using:
DynaActionForm taxRatesForm = new DynaActionForm();
and
taxRatesForm.set("taxRates", allTaxRates); request.setAttribute("taxRates",
allTaxRates);

Creating a form in the action servlet is one sure way to piss the folks off who have to maintain the app. You might think its big n clever, but you'd be hiding the form away in a class, what do the htmlists do?



<form-property name="taxRate" type="java.util.ArrayList" />


Using arraylist means you dont have to use the lazy list initialization that i think that using an array will require. See bean utils for details. I could be full of shit but I have this working with arrayList and no joy with using arrays of beans.

DynaActionForm theForm = (DynaActionForm) form;

ArrayList rateList = new ArrayList();

Iterator it = getSomeStuffFromMyModel();

while(it.hasMoreElements()) {
        rateList.add(it.next());
}

theForm.set("taxRate",rateList);

request.setAttribute("taxRate",rateList);



This will prepopulate the the array and put the form in the request.


Specifying the name="formName" in the action will just give you the form as
the parameter to the execute method. The alternative is to create it
yourself with 'new'.


I think you have the choice of putting the form in either session or request
scope. Request scope is generally preferable b/c the memory gets released
sooner.

Yeah right .. Nullpointerexception tastic. Last I looked scoping to request wont work , so don't bother.



I'm not clear on the need to put allTaxRates in session scope. Can you send
your JSP code?

<action name="/process.do" name="myForm" scope="session" .. in jsp

<logic:iterate id="rate" name="myForm" property="taxRate">
        <html:text name="rate" property="myproperty" />

I think I've posted this about 60,000 times in just a matter of months so i guess one more wont hurt.

Cheers Mark



-Richard



-----Original Message-----
From: Matt Bathje [mailto:[EMAIL PROTECTED]
Sent: Friday, November 21, 2003 7:37 AM
To: Struts Users Mailing List
Subject: Re: dynamically sized form (mostly solved)


Might I say - woohoo!!


Thanks to your guys help, I got this working. I just want to make sure that
I'm doing this the best way.


In my struts-config file, the preloader has to have the form named in
addition to having it on the action. The form is setup to be in the request
scope, not in the session scope.


In my preloader action, instead of doing

DynaActionForm taxRatesForm = new DynaActionForm();

I do:

DynaActionForm taxRatesForm = (DynaActionForm) form;

then I just do:
taxRatesForm.set("taxRates", allTaxRates); request.setAttribute("taxRates",
allTaxRates);


In the submit action, I just have to do:
DynaActionForm taxRatesForm = (DynaActionForm) form; TaxRateBean[] taxRates
=
(TaxRateBean[]) taxRateForm.get("taxRates");


Everything seems to work pretty slickly. My main question is
if having to have the name="formName" in the preloader
action is correct? It would be nice to know if I am doing anything else the
"incorrect" way though also. If I didn't explain anything very well and you
want to see code snippets, just let me know.


Thanks,
Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to