You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vincent Stoessel <vi...@xaymaca.com> on 2002/10/01 00:49:58 UTC

okay, one more time for the slow people...

How do you use the DyanActionForm in the action classes.
I saw 2 different examples in the archive, neither of which worked for
me.

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


gives me this compile error:

AddUserAction.java [48:1] incompatible types
found   : org.apache.commons.beanutils.DynaBean
required: org.apache.struts.action.DynaActionForm

line 48 : DynaActionForm myForm = dafc.newInstance();


What is the official way?
Thanks.



Thanks
-- 
Vincent Stoessel
Linux Systems Developer
vincent xaymaca.com


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


Re: okay, one more time for the slow people...

Posted by "V. Cekvenich" <vi...@users.sourceforge.net>.
The other way is:
public Object onDisplayZoomExec(ActionEvent ae) throws Exception
{
String id = ae.getReq().getParameter(ID); // the PK is?
long ia = BUtil.longString(id);
		
TasksBean frm  = (TasksBean) ((TilesEvent)ae).getFormBean();
		
setBBean( frm );
getBBean().findSingle(ia); // hard code for now
		
ae.getReq().setAttribute(FORMBEAN, getBBean());

return ((TilesEvent)ae).getMapping().findForward("Zoom");
}


KISS, the code does not need UML or even comments or design.
Keep it simple, complex != good or fast
This code is also more portable to another MVC framework, ex. JSF (one 
reason is that controlers is an interface, in this exmple at the tile 
level, so each tile has it's own events)
Note use of event object, and auto dispatching of events. This gets 
consumed by the JSTL tags. Also the bean, which you can't see here calls 
DAO .retrieve() in its findX ().
(code from the Struts basicPortal on sf.net)

.V
(Struts mentor 
http://www.mail-archive.com/mvc-programmers%40basebeans.com/msg00242.html
)



Eddie Bush wrote:
> - Declare your form to be of type DynaActionForm in struts-config
> - Declare your properties to be of whatever type they need to be
> - Preface the page call with an action which will cast the "form" 
> argument to be a DynaActionForm
> - call form.set("property", value) as needed
> - forward to the page that will use the form
> 
> Chapter 5 pg 20 of Chuck's book covers this quite well. (That may not be 
> exact, but it's close)
> 
> I'm not going to claim it's "the official way" - but it's often done 
> this way, for sure.  Follow Chuck's example.  Remember that (unless you 
> have extenuating circumstances - most of the time pre-population does 
> not qualify) you should never have to create a form yourself.  Expect it 
> to be there.  If it's not, double-check your config to ensure you told 
> Struts to make sure it was there.  If you have done that and it didn't 
> let it NPE and then file a bug report.
> 
> Vincent Stoessel wrote:
> 
>> How do you use the DyanActionForm in the action classes.
>> I saw 2 different examples in the archive, neither of which worked for
>> me.
>>
>>     DynaActionFormClass dafc = 
>> DynaActionFormClass.getDynaActionFormClass("AddUserForm");
>>     DynaActionForm myForm = dafc.newInstance();
>>
>>
>> gives me this compile error:
>>
>> AddUserAction.java [48:1] incompatible types
>> found   : org.apache.commons.beanutils.DynaBean
>> required: org.apache.struts.action.DynaActionForm
>>
>> line 48 : DynaActionForm myForm = dafc.newInstance();
>>
>>
>> What is the official way?
>> Thanks.
> 
> 
> 




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


Re: okay, one more time for the slow people...

Posted by Eddie Bush <ek...@swbell.net>.
- Declare your form to be of type DynaActionForm in struts-config
- Declare your properties to be of whatever type they need to be
- Preface the page call with an action which will cast the "form" 
argument to be a DynaActionForm
- call form.set("property", value) as needed
- forward to the page that will use the form

Chapter 5 pg 20 of Chuck's book covers this quite well. (That may not be 
exact, but it's close)

I'm not going to claim it's "the official way" - but it's often done 
this way, for sure.  Follow Chuck's example.  Remember that (unless you 
have extenuating circumstances - most of the time pre-population does 
not qualify) you should never have to create a form yourself.  Expect it 
to be there.  If it's not, double-check your config to ensure you told 
Struts to make sure it was there.  If you have done that and it didn't 
let it NPE and then file a bug report.

Vincent Stoessel wrote:

> How do you use the DyanActionForm in the action classes.
> I saw 2 different examples in the archive, neither of which worked for
> me.
>
>     DynaActionFormClass dafc = 
> DynaActionFormClass.getDynaActionFormClass("AddUserForm");
>     DynaActionForm myForm = dafc.newInstance();
>
>
> gives me this compile error:
>
> AddUserAction.java [48:1] incompatible types
> found   : org.apache.commons.beanutils.DynaBean
> required: org.apache.struts.action.DynaActionForm
>
> line 48 : DynaActionForm myForm = dafc.newInstance();
>
>
> What is the official way?
> Thanks.


-- 
Eddie Bush




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