I've defined and I'm using a subclass of Action (my.package.BaseAction), in order to implement the Template design pattern, so I use this class instead of the Action class provided by STRUTS. The intended goal is that things that are common to all actions are performed here, such as logging and validation of the user's session, some postprocessing, etc. In that class I've declared the execute(..) method as final, so that no subclass can override it:

public final ActionForward execute(
                ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response)
                throws Exception {

        _log = Logger.getLogger(this.getClass());
        if (_log.isDebugEnabled()) {
                _log.debug(someString);
        }

        try {
                // Check for precondition errors; fail if found
                if (preProcess(mapping,form,request,response)) {
                        // Execute actual logic
                        ActionForward forward = 
executeLogic(mapping,form,request,response);
                }
                // Some postprocessing...
                postProcess(mapping,form,request,response);

return forward;

        } catch (SessionNotValidActionException se) {
                if (_log.isDebugEnabled()) {
                        _log.debug("Session is not valid, redirecting to login.");
                }
                return mapping.findForward("login");
        } catch (...) {
                ...
        } finally {
                ...
        }

        if (_log.isDebugEnabled()) {
                _log.debug("Leaving execute method.");
        }
}

and I provide the two methods - preProcess and postProcess - together with an abstract executeLogic method, and some other common helper needs into utility methods.

But Actions classes are often too small, and this ruins the cohesiveness of the application. So I would like to start employing DispactchAction classes to group related actions. Do you have any suggestion on how to implement the above approach (template pattern) to extend DispatchAction, in order to define a BaseDispatchAction?

Thanks,
Gianluca


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



Reply via email to