> Instead, I am experimenting with overriding the struts
> processActionForm() to notice when the form is created and call a
> form.create() method on my ActionForm subclass, passing the
> request/session in at that time.  This seems to be working nicely - i
> still have to have all requests for the page containing the form
> accessed by an action to force initialization before the form is
> displayed, but I have only one action class for all forms and the
> initialization logic stays where it belongs - inside the form.
>
> I'm curious if others think having a form.create() method would be
> useful, and if so, if there is a possibiliy to incorporate it into the
> struts core?
>
> I guess the signature would look like
>
>   void create(HttpServletRequest request)
>
> and it would be called each time a new action form bean instance is
> created, on the instance created.

How about a hook in the Action class instead of the ActionForm. I think you
bring up a good idea, but I also think that initializing a form could be
complex at times, forcing the ActionForm to be aware (coupled) to those
components that are used for initialization. It is my understanding that an
ActionForm is supposed to be a simple data structure that has a one-to-one
mapping to each field on the form. It is also supposed to perform _simple_
validation on those fields. The Action class, on the other hand, is
responsible for processing ActionForm. As suggested on this email list, I
don't think that the ActionForm itself should actually implement all the
processing (instead use SessionBeans, EntityBeans, JavaBeans, etc...). So,
if there were a hook in the Action class, call it Action.initForm(ActionForm
form) throws SomeException, that could be guaranteed to be called only once
(when the form was created), then IMHO I think that would be an appropriate
solution. The Action class is already coupled to the form through the
various perform  methods and in that respect I don't think any OO concepts
are bent.

My $0.02 worth.

Robert

Reply via email to