You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Axel Stahlhut <as...@neusta.de> on 2002/07/30 14:03:32 UTC

DynaActionForm and reset method called always

Hi.

I switched to Struts1.1 beta now and I wonder if there is a way to avoid the framework from resetting the DynaActionForm on every request. This is because i reshow the view to the user to commit the data. The, in the second request, which is not send by a form, i wnat to insert the values inside the FormBean into the business tier. With the "old" FormBeans, everything worked out fine, because I didnt implement reset(...).

The DynaActionForms are always resetted. Is there a way to prevent this without deriving? If not, what is this DynaActionClass about? If i simply derive DynaActionForm and overwrite reset(...), i get a null pointer exception in here:
     sb.append(getDynaClass().getName());

Who or what sets the dynaClass-member?

Greets Axel



Re: DynaActionForm and reset method called always

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 30 Jul 2002, Axel Stahlhut wrote:

> Date: Tue, 30 Jul 2002 14:03:32 +0200
> From: Axel Stahlhut <as...@neusta.de>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: DynaActionForm and reset method called always
>
> Hi.
>
> I switched to Struts1.1 beta now and I wonder if there is a way to avoid
> the framework from resetting the DynaActionForm on every request. This
> is because i reshow the view to the user to commit the data. The, in the
> second request, which is not send by a form, i wnat to insert the values
> inside the FormBean into the business tier. With the "old" FormBeans,
> everything worked out fine, because I didnt implement reset(...).
>

It's not just DynaActionForms that get their reset() method called -- all
form beans do.  The default implementation in ActionForm does nothing.

If you don't like what the default reset() method does, you can subclass
DynaActionForm and implement your own.

> The DynaActionForms are always resetted. Is there a way to prevent this
> without deriving?

No.

> If not, what is this DynaActionClass about? If i
> simply derive DynaActionForm and overwrite reset(...), i get a null
> pointer exception in here:
>      sb.append(getDynaClass().getName());
>
> Who or what sets the dynaClass-member?
>

The detailed answer needs to be based on some knowledge from the JavaDoc
APIs for org.apache.commons.beanutils -- there is an extensive discussion
of what DynaClass is for, and different ways it can be used:

  http://jakarta.apache.org/commons/beanutils/api/

But basically, a DynaClass acts (to a DynaBean) sort of like how a Class
acts to a regular JavaBean.  In particular, it provides a definition of
all the valid properties (and their types), that can be "introspected" by
things like BeanUtils so that the populate() method still works.

In Struts, each dynamic form bean has its own set of properties, but all
instances of the same form bean have the same set -- so it was natural to
map the list of properties defined with <form-property> elements into a
DynaClass.  Because form bean names have to be unique anyway, it also
seemed convenient to use that as the "class name" of the DynaClass.

As to who populates the "dynaClass" member, you will find that Struts uses
the newInstance() method of the appropriate DynaActionFormClass for this
form bean, which (among other things) sets this value.

In Struts, the purpose of a DynaActionClass is to keep the table of valid
properties for a particular form bean in one place

> Greets Axel
>
>
>

Craig



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