On Mon, 22 Jul 2002, Matt Raible wrote:

> Date: Mon, 22 Jul 2002 18:40:56 -0600
> From: Matt Raible <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: NPE when setting values on DynaActionForm
>
> I want to populate a DynaActionForm before dispatching to a JSP, however
> the following doesn't work:
>
> DynaActionForm requestForm = new DynaActionForm();
> requestForm.set("subject", subject);
> requestForm.set("content", content);
> requestForm.set("courseId", cForm.getCourseId());
> requestForm.set("courseName", cForm.getName());
>
> I get a NPE at the first .set - here is my configuration:
>

This won't work because the DynaActionForm you created doesn't know what
the set of valid properties are.

>         <form-bean name="requestForm"
> type="org.apache.struts.action.DynaActionForm">
>             <form-property name="action" type="java.lang.String"/>
>             <form-property name="courseId" type="java.lang.String"/>
>             <form-property name="courseName" type="java.lang.String"/>
>             <form-property name="type" type="java.lang.String"/>
>             <form-property name="subject" type="java.lang.String"/>
>             <form-property name="content" type="java.lang.String"/>
>             <form-property name="message" type="java.lang.String"/>
>         </form-bean>
>
> Should it?
>

With the current APIs, it is surprisingly hard to do this, because there
is no convenient way to get to the underlying DynaActionFormClass
instance.  I"m going to be adding some API in tonight's nightly build so
that you will be able to say:

  DynaActionForm requestForm =
     DynaActionFormClass.getDynaClass("requestForm").newInstance();

to get a DynaActionForm initalized with the correct properties.  In the
mean time, a workaround is to declare that your "setup" action also uses
this form bean (so that Struts will set it up for you), or go through the
following exercise:

    ApplicationConfig appConfig = (ApplicationConfig)
      request.getAttribute(Action.APPLICATION_KEY);
    FormBeanConfig fbConfig = appConfig.findFormBeanConfig("requestForm");
    DynaActionForm requestForm =
      DynaActionFormClass.createDynaActionFormClass(fbConfig).newInstance();

> Thanks,
>
> Matt
>

Craig


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

Reply via email to