You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Volker Krebs <vo...@abas.de> on 2002/01/22 14:40:49 UTC
ActionForm Instance when using DynaBeans
Hello,
on the user list nobody could help me with my Problem
about DynaBeans. So I'll give it a try on this list.
In my Application, FormBeans are not simply
the representation of HTML Forms, we sometimes
use them as ValueObjects/DataContainers/DataObjects
(you know what I mean)
Therefore it is sometimes necessary to create
new Form Beans in our Actions. With normal
FormBeans this is obviously no problem, but
how to create DynaActionForm ?
The only way I've found to create them is
ApplicationConfig appConfig =
(ApplicationConfig)request.getAttribute(Action.APPLICATION_KEY);
DynaActionFormClass dynActFoClass =
DynaActionFormClass.createDynaActionFormClass(appConfig.findFormBeanConfig("userForm"));
DynaActionForm dynaForm = new DynaActionForm();
dynaForm.setDynaActionFormClass(dynActFoClass);
But this doesn't wotk because setDynaActionFormClass is private.
Is there another way to create DynaActionFormClass ?
Or is there a general problem using FormBeans as
ValueObjects ?
thanks,
Volker
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ActionForm Instance when using DynaBeans
Posted by Volker Krebs <vo...@abas.de>.
Hello,
>>on my own and send it to the JSP Page. E.g. when I want
>>a html form to be initialized with some values.
>>
> The traditional Struts design pattern for this (with either standard or
> dynamic form beans) is to do the setup in a "setup" action that creates
> the form bean, populates its properties, sticks it in request scope, and
> forwards to the page. In the Struts example app, that's what the
> "/editRegistration" and "/editSubscription" actions do, for example.
>
Yes thats exactlly what I do,
but I need to create a new FormBean or DynaFormBean then.
In the examples you have
form = new SubscriptionForm();
or
form = new RegistrationForm();
When these two FormBeans are converted to DynaFormBeans,
you have to use BasicDynaBean because there
is no way to create a new DynaActionForm in an Action.
regards
Volker
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ActionForm Instance when using DynaBeans
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Wed, 23 Jan 2002, Volker Krebs wrote:
> Date: Wed, 23 Jan 2002 11:00:39 +0100
> From: Volker Krebs <vo...@abas.de>
> Reply-To: Struts Developers List <st...@jakarta.apache.org>
> To: Struts Developers List <st...@jakarta.apache.org>
> Subject: Re: ActionForm Instance when using DynaBeans
>
> >>Is there another way to create DynaActionFormClass ?
> >>Or is there a general problem using FormBeans as
> >>ValueObjects ?
> >>
> > As above, the restrictions are deliberate. Use regular value objects
> > (either standard JavaBeans or DynaBeans) and create references to them as
> > necessary in your form beans.
> >
>
>
> But there are Situations when I have to create a FormBean
>
You might want to look at DynaActionForm in the latest nightly builds.
The general idea is that most people will use the provided class
(org.apache.stuts.action.DynaActionForm) as is -- the only reason you'd
need to subclass is if you wanted to provide your own reset() and/or
validate() methods.
> on my own and send it to the JSP Page. E.g. when I want
> a html form to be initialized with some values.
>
The traditional Struts design pattern for this (with either standard or
dynamic form beans) is to do the setup in a "setup" action that creates
the form bean, populates its properties, sticks it in request scope, and
forwards to the page. In the Struts example app, that's what the
"/editRegistration" and "/editSubscription" actions do, for example.
> In case of DynaBeans I'll have to use BasicDynaBean then.
>
> Volker
>
Craig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ActionForm Instance when using DynaBeans
Posted by Volker Krebs <vo...@abas.de>.
>>Is there another way to create DynaActionFormClass ?
>>Or is there a general problem using FormBeans as
>>ValueObjects ?
>>
> As above, the restrictions are deliberate. Use regular value objects
> (either standard JavaBeans or DynaBeans) and create references to them as
> necessary in your form beans.
>
But there are Situations when I have to create a FormBean
on my own and send it to the JSP Page. E.g. when I want
a html form to be initialized with some values.
In case of DynaBeans I'll have to use BasicDynaBean then.
Volker
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: ActionForm Instance when using DynaBeans
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Tue, 22 Jan 2002, Volker Krebs wrote:
> Date: Tue, 22 Jan 2002 14:40:49 +0100
> From: Volker Krebs <vo...@abas.de>
> Reply-To: Struts Developers List <st...@jakarta.apache.org>
> To: struts-dev@jakarta.apache.org
> Subject: ActionForm Instance when using DynaBeans
>
> Hello,
>
> on the user list nobody could help me with my Problem
> about DynaBeans. So I'll give it a try on this list.
>
> In my Application, FormBeans are not simply
> the representation of HTML Forms, we sometimes
> use them as ValueObjects/DataContainers/DataObjects
> (you know what I mean)
>
Yes, we know ... and ActionForm's original design (as a class, not an
interface) was specifically designed to discourage you from doing this.
It is *not* a good design approach. The same applies to DynaActionForms.
ActionForm semantics are defined to be what Struts needs (maintain string
representation of non-string properties, reset() and validate(), and so
on). They do not correspond to what you need for a general purpose value
object. If you want to use DynaBeans for value objects, the simplest
thing to do is use BasicDynaBean and BasicDynaClass directly:
BasicDynaClass myClass = new BasicDynaClass("MyClass",
{ new DynaProperty("name", "java.lang.String"),
new DynaProperty("streetAddress", "java.lang.String"),
...
new DynaProperty("hireDate", "java.util.Date") });
Object myBean = myClass.newInstance();
> Therefore it is sometimes necessary to create
> new Form Beans in our Actions. With normal
> FormBeans this is obviously no problem, but
> how to create DynaActionForm ?
>
> The only way I've found to create them is
>
> ApplicationConfig appConfig =
> (ApplicationConfig)request.getAttribute(Action.APPLICATION_KEY);
> DynaActionFormClass dynActFoClass =
> DynaActionFormClass.createDynaActionFormClass(appConfig.findFormBeanConfig("userForm"));
> DynaActionForm dynaForm = new DynaActionForm();
> dynaForm.setDynaActionFormClass(dynActFoClass);
>
> But this doesn't wotk because setDynaActionFormClass is private.
>
> Is there another way to create DynaActionFormClass ?
> Or is there a general problem using FormBeans as
> ValueObjects ?
>
As above, the restrictions are deliberate. Use regular value objects
(either standard JavaBeans or DynaBeans) and create references to them as
necessary in your form beans.
> thanks,
>
> Volker
>
Craig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>