Another approach, similar to the others suggested, is to define the
eqivalent of a postProcess() action. The base Action class does its
perform business, and if all is well, then returns the result of the new
method. This also allows you to change the signature of your new method,
if there is ever any reason for that. One example would be to pass a
login object from the session if that was used in all or most of the
Actions. 

    public ActionForward perform(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
    throws IOException, ServletException {

        // Application specific behaviour
        // if everything is kosher call subclass

        return ( performAction(mapping,form,request,response, myParameter ) )
   }

   where performAction is an abstract method of the base class.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/about/struts/



"Hicks, James" wrote:
> 
> I would like to suggest adding a method called prePerform to match each
> perform method in the org.apache.struts.action.Action class and have the
> ActionServlet call it just before it calls perform.  These prePerform method
> would also return an ActionForward instance.  If the ActionServlet received
> an ActionForward from the prePerform, it would use it to forward the request
> instead of calling the perform method.
> 
> This would ease development in a lot of projects.
> 
> For example, say I want to validate my visitor on each request.  If I had a
> prePerform method I could write a subclass of Action for my project called
> MyProjectBaseAction and include the prePerform method.  Inside of
> prePerform, I could do the validation.  This would allow me to take the
> validation code out of each one of my specific action classes and never have
> to worry about the validation logic changing.  If it did change, I have one
> place to change it instead of 50 or 100.
> 
> James Hicks

Reply via email to