> Then each action would implement our 2 parameter show method, and return
> a String which could be passed to the ActionMapping by the CommonAction
> superclass. This would significantly simplify the code in our Action
> classes, reducing repetition between each one, and ensuring that they
> each follow all the required auditing and security checks.

Since your submit also shares the same duplicate code. Instead of
having "show", "submit" and other methods having the same code in the
CommonAction, you can override the "execute" method.

> 
> I'm wondering if it's considered a bad idea to have the
> MappingDispatchAction's dispatch method invoke a call on the superclass
> which in turn delegates to the subclass after executing all the common
> stuff, because all our subclasses would have a different method
> signature than that which is standard in Struts. 

Well, delegating some work to the superclass method and then calling
the subclass method is is a good practice. But I would be careful in
changing the signature of the method. What if the subclass method
requires some special processing to do based on the request
parameters? So, I would like to keep the signature exactly the same.

Or is it acceptable to
> do this because our CommonAction class will insulate us from any
> potential changes to Struts which would affect this method signature.
> 

Well, if Struts method signature changes, you would have to change the
super class show method anyway.

My version of your Common Action would be
public class CommonAction extends MappingDispatchAction{

public static final String SUCCESS = "success";
public static final String FAILURE = "failure";

  public ActionForward execute(ActionMapping mapping, 
                               ActionForm form, 
                               HttpServletRequest request, 
                               HttpServletResponse response){
    
    log.debug(">> " + mapping.getParameter());
    
    // Audit logging, log the details of the user and their requested action
    // Security check, check they are allowed to execute the action
    // Set up page header details from model
    // Execute specific action code
    
    ActionForward forward = super.execute(mapping, form, request, response);

    log.debug("<< " + mapping.getParameter());
 
    return forward;
  }
}

and the subclasses of the common action would have show and update
methods with the same signature as execute

  public ActionForward show(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
    // show logic
    return mapping.findForward(SUCCESS);
  }
  public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
    // update logic
    return mapping.findForward(SUCCESS);
  }

Now, I put common code in the execute of the CommonAction. If there
are any differences in the common code b/n different methods (show,
update), you can have show & update methods in the CommonAction and
can have the subclasses overriding those methods and calling
super.execute().

Thanks,
Kishore Senji.

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

Reply via email to