struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Creating a DynaActionForm instance
Date Thu, 29 Aug 2002 05:15:09 GMT


On Thu, 29 Aug 2002, Aaron Lindsey wrote:

> Date: Thu, 29 Aug 2002 00:09:28 -0400
> From: Aaron Lindsey <aaron.lindsey@objectsciences.com>
> Reply-To: Struts Users Mailing List <struts-user@jakarta.apache.org>,
>      aaron.lindsey@objectsciences.com
> To: struts-user@jakarta.apache.org
> Subject: Creating a DynaActionForm instance
>
> Hi all,
>    I've seen this question asked a couple of times in the archives, but there
> weren't any answers that I could find, so I'm giving it another shot.  How
> can I create an instance of DynaActionForm from inside an Action in order to
> prepopulate it with data to be displayed in a jsp form?  I tried the
> following:
>
> DynaActionForm myForm = new DynaActionForm();
> myForm.set("firstName", "bob");
>
> A NullPointerException is thrown.  Is it possible to do something like this
> with a DynaActionForm?  Do I have to go back to the regular ActionForm to
> have the ability to create an instance of an ActionForm, populate it, put it
> on the Request, and forward to a jsp that will then use the form?  Thanks.
>

To create a new DynaActionForm instance, you *must* ask for a new instance
from the corresponding DynaActionFormClass.  Otherwise, the DynaActionForm
instance will not know what it's valid properties are:

    DynaActionFormClass dafc =
	DynaActionFormClass.getDynaActionFormClass("formBeanName");
    DynaActionForm myForm = dafc.newInstance();

> Aaron

Craig


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message