> -----Original Message-----
> From: Ted Husted [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, July 13, 2005 3:22 PM
> To: Struts Users Mailing List
> Subject: Re: Putting execute() in ActionForm
> 
> [snip]
> 
> If I were to use this strategy, I'd select the parameters to the
> Execute signature with care. There may not be any reason to pass the
> HTTP parameters out of the call, and there may be a reason  to pass
> the Action. I would just be careful of using the parameters from the
> Struts Execute signature, unless my code actually needed those
> parameters..

I have found that I do need the Action available to the ActionForm's execute 
method, because the Action class contains several important utility methods 
(like saveErrors(), etc.) that need to be available to the ActionForm's execute 
method.

Further, since there is a separate ActionForm instance for each thread, I've 
considered adding the ActionMapping and HttpServletRequest as instance 
variables on the ActionForm, which are populated by the Action method before 
invoking ActionForm.execute():

public class SimpleAction extends Action {
  public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
                SimpleActionForm bean = (SimpleActionForm) form;
                bean.init(this, mapping, request);
                return bean.execute();
      }
}

I realize this would not be a safe approach if there are situations where a 
SimpleActionForm could have multiple threads running through it. I've seen 
references to situations where session-scoped ActionForms can be accessed 
concurrently by multiple requests. However, I can't think of any common 
situations where that could occur -- at least, not in the sort of applications 
I'm writing. And, of course it would never occur with request-scoped 
ActionForms.

> 
> I also wouldn't hestitate to put some "traffic cop" code into the base
> Action as needed, so that the ActionForm execute can focus on what it
> needs to do, rather than what the application needs to do.
> 
> I'd also consider using a base ActionForm with all the properties my
> application needs, which I could then extend with execute and validate
> methods, as needed.
> 
> Though, I'd probably use a DynaActionForm instead of a conventional
> ActionForm as the base class, just for the agility.

These suggestions make sense to me.

> 
> Most importantly, I'd make very sure that all my "code-behind
> ActionForms" were request scope, probably by changing the factory
> default.

Can you elaborate on this? Why the strong recommendation for request scope? Is 
it because of threading concerns related to session-scoped ActionForms that I 
mentioned above? 

By the way, I'm very interested in all of the feedback on my request for input 
on this pattern.  If this is considered a desirable pattern, would it be worth 
adding it on the Struts wiki?

Stephen

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to