On Tue, 22 Jan 2002, Volker Krebs wrote:
> Date: Tue, 22 Jan 2002 14:40:49 +0100
> From: Volker Krebs <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> 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: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>