You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Affan Qureshi <qu...@etilize.com> on 2002/12/21 14:12:26 UTC

Re: Pre-populating DynaActionForm Bean (solved)

Should use the following way to instantiate a DynaActionForm:

DynaBean form =
DynaActionFormClass.getDynaActionFormClass("accessory").newInstance();

But surprisingly i can't find this method on the API on the Docs on the
struts website. http://jakarta.apache.org/struts/api/index.html

Thanks,

Affan

----- Original Message -----
From: "Affan Qureshi" <qu...@etilize.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Saturday, December 21, 2002 4:33 PM
Subject: Re: Pre-populating DynaActionForm Bean


> I have a similar scenario but in my case the sending action does not have
> the same form bean bean associated as the destination. So what I want to
do
> is to instantiate a form bean which the JSP is expecting and put it in the
> request scope.
>
> Here is my code:
>
> DynaActionForm form = new DynaActionForm();
> form.set("productId", String.valueOf(acc.getProductId()));
> form.set("mfrPartNumber", acc.getAccessoryProduct().getMfgPartNo());
> form.set("description", acc.getAccessoryProduct().getDescription());
> form.set("notes", acc.getNotes());
> req.setAttribute("accessory", form);
>
> This is the JSP to which I am sending this request:
> <html:form action="saveAcc.do" method="GET" >
>             <html:text property="productId"
size="25"readonly="true"/></td>
>             <html:text property="mfrPartNumber" size="25"/></td>
>             <html:text property="description" size="25"/></td>
>             <html:textarea property="notes" rows="8"/></td>
>             <html:submit >Save Accessory</html:submit>
>     </html:form>
>
> In struts-config.xml I have the following def for action saveAcc.do
> <action path="/saveAcc" type="my.mypackage.MySaveAccessoryAction"
> name="accessory" validate="false" scope="request">
>
> This is the error I get when submitting to the JSP:
> java.lang.NullPointerException at
>
org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:
> 545) at
org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:361)
> at com.etilize.cms.web.actions.AddAccessoriesAction.editAccessory ......
> (more...)
>
> I am sorry if this has come up earlier but I could not find one.
>
> Thanks a lot.
> Affan



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Pre-populating DynaActionForm Bean (solved)

Posted by Dan Allen <da...@mojavelinux.com>.
> Thus, the fact that this is an undocumented method and not used in the
> struts example application, leads me to believe my understanding is wrong.
> How would one grab data from a database and use that data to populate a form
> in struts?

You request an action mapping, such as

/EditAccount

and in that Action (EditAccountAction), which is passed a reference
to your form, you use BeanUtils.copyProperties or whatever to
transfer the data into your form and then you forward to your form
page.  Then you submit it and do the reverse on an action like

/SaveAccountChanges

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Microsoft is not the answer, it is the question. 
The answer is NO!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: Pre-populating DynaActionForm Bean (solved)

Posted by Dave Ford <df...@smart-soft.com>.
> Should use the following way to instantiate a DynaActionForm:
>
> DynaBean form =
> DynaActionFormClass.getDynaActionFormClass("accessory").newInstance();
>
> But surprisingly i can't find this method on the API on the Docs on the
> struts website. http://jakarta.apache.org/struts/api/index.html

Maybe I'm missing something. But I thought the primary purpose of the form
bean was to re-populate forms, but also to POPULATE forms (without the re).
How can one do this without the being able to create a DynaActionForm
instance? My understanding is that almost every struts application would
need this capability. For example: grab data from a database to populate a
form.

Thus, the fact that this is an undocumented method and not used in the
struts example application, leads me to believe my understanding is wrong.
How would one grab data from a database and use that data to populate a form
in struts?

Thanks.

Dave Ford
Smart Soft - The Developer Training Company
http://www.smart-soft.com



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