I was searching around and found a very long thread in the struts-dev mailing
list (of which I am not a member) about how to instantiate both ActionForm
and DynaActionForm objects in order to pre-populate a form (see below for a
snippet of that thread).
My questions is, why go to all the trouble of instantiating the form yourself
in your Action, when the ActionServlet will do this for you if you specify
the form-bean name in the struts-config.xml mapping for that Action (and you
would specify validate=false, since you are forwarding to the form from this
Action, not handling a submitted form). Then, the correctly instantiated
ActionForm/DynaActionForm already exists and you just have to fill in the
pre-population values.
I must be missing something, because it seems like a lot of people are trying
to figure out how to instantiate forms, especially Dyna*Form objects, in
order to pre-populate. And if I am correct, then why are people doing this ?
- Charlie
On Wed, 8 Jan 2003, Franco Caponi wrote:
> Date: Wed, 8 Jan 2003 18:06:06 +0100
> From: Franco Caponi <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: Struts Developers List <[EMAIL PROTECTED]>
> Subject: Re: DynaActionFormClass.getDynaActionFormClass
>
> Hi Craig,
> I have tha same problem: from an Action class i need to create the
> ActionForm associated with a particular mapping and populate some properties
> before returning the correct ActionForward, but i don't know how call the
> suggested RequestUtils.createActionForm().
>
> My problem is how to supply the ActionMapping parameter because i have found
> only the findActionConfig on the ModuleConfig that return a superclass of
> ActionMapping.
>
> Calling it with a cast to ActionMapping generate a NullPointerException...
>
You should get a ClassCastException if this were really an instance type
problem. Without the stack trace, it's impossible to know what is really
happening.
> Can you supply a simple example/ How to??
>
Here's an additional technique that is a little more work, but just starts
with a ModuleConfig and a form bean name.
ModuleConfig mconfig = ... ModuleConfig for the current module
FormBeanConfig fbconfig = mconfig.findFormBeanConfig("foo");
DynaActionFormClass dafc =
new DynaActionFormClass(fbconfig);
DynaActionForm daf = dafc.newInstance();
> TIA
>
Craig
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>