You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Scott Purcell <sp...@vertisinc.com> on 2005/04/07 23:01:09 UTC

DispatchAction Need to Subclass Help

Hello,
 
In an application that I am coding, I had the need to subclass the Action class in order to take care of some session handling. 
 
So I subclass this type scenario in all my action classes:
 
######
abstract public class BaseActionUA extends Action  {
 

  public ActionForward execute(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
    throws Exception {
 
    return executeAction(mapping, form, request, response, getAppObject(request, response), getUserObject(request, response));
  }
 

  /** method that must be overriden by the subclasses. */
  abstract public ActionForward executeAction(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response,
                               AppObject appObject,
                               UserObject userObject)
    throws Exception;
 
 
 
All is good with that. But I have created quite a few action classes, and would like to try implementing the DispatchAction class to eliminate some of the "c.r.u.d" type of actions.
 
The problem I have is I cannot figure out how to subclass this and add in my needed functionality, because it looks like it just wants a clean action and I need (currently) to use something like a executeAction subclass method call.
 
 
Does anyone have any information in regards to using this?
 
Thanks,
Scott

Re: DispatchAction Need to Subclass Help

Posted by Hubert Rabago <hr...@gmail.com>.
Take a look at the ActionDispatcher class attached to
http://issues.apache.org/bugzilla/attachment.cgi?id=12768 .
The javadoc of that class explains how it's used.

Hubert

On Apr 7, 2005 4:01 PM, Scott Purcell <sp...@vertisinc.com> wrote:
> Hello,
> 
> In an application that I am coding, I had the need to subclass the Action class in order to take care of some session handling.
> 
> So I subclass this type scenario in all my action classes:
> 
> ######
> abstract public class BaseActionUA extends Action  {
> 
>   public ActionForward execute(ActionMapping mapping,
>                                ActionForm form,
>                                HttpServletRequest request,
>                                HttpServletResponse response)
>     throws Exception {
> 
>     return executeAction(mapping, form, request, response, getAppObject(request, response), getUserObject(request, response));
>   }
> 
>   /** method that must be overriden by the subclasses. */
>   abstract public ActionForward executeAction(ActionMapping mapping,
>                                ActionForm form,
>                                HttpServletRequest request,
>                                HttpServletResponse response,
>                                AppObject appObject,
>                                UserObject userObject)
>     throws Exception;
> 
> All is good with that. But I have created quite a few action classes, and would like to try implementing the DispatchAction class to eliminate some of the "c.r.u.d" type of actions.
> 
> The problem I have is I cannot figure out how to subclass this and add in my needed functionality, because it looks like it just wants a clean action and I need (currently) to use something like a executeAction subclass method call.
> 
> Does anyone have any information in regards to using this?
> 
> Thanks,
> Scott
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: DispatchAction Need to Subclass Help

Posted by Rick Reumann <st...@reumann.net>.
Would it work for you if you changed your BaseActionUA class to extend 
DispatchAction instead of Action and then in your execute you'll have to 
do a bit of logic to decide if you want to act as your standard Action 
(and in your case call executeAction method) or instead call super(...) 
and thus behave as standard DispatchAction?

So your execute in BaseActionUA might look like...

execute(..) {
	String parameter = mapping.getParameter();
         if (parameter != null) {
		super.execute(mapping,.... );
         }
         else {
            return executeAction(mapping,...);
         }
}

I 'think' the above might do what you want, but not positive. You Base 
Action would thus act as your standard BaseAction or would act as a 
DispatchAction given that the proper dispatch parameter was passed in 
the request.


Scott Purcell wrote the following on 4/7/2005 5:01 PM:
> Hello,
>  
> In an application that I am coding, I had the need to subclass the Action class in order to take care of some session handling. 
>  
> So I subclass this type scenario in all my action classes:
>  
> ######
> abstract public class BaseActionUA extends Action  {
>  
> 
>   public ActionForward execute(ActionMapping mapping,
>                                ActionForm form,
>                                HttpServletRequest request,
>                                HttpServletResponse response)
>     throws Exception {
>  
>     return executeAction(mapping, form, request, response, getAppObject(request, response), getUserObject(request, response));
>   }
>  
> 
>   /** method that must be overriden by the subclasses. */
>   abstract public ActionForward executeAction(ActionMapping mapping,
>                                ActionForm form,
>                                HttpServletRequest request,
>                                HttpServletResponse response,
>                                AppObject appObject,
>                                UserObject userObject)
>     throws Exception;
>  
>  
>  
> All is good with that. But I have created quite a few action classes, and would like to try implementing the DispatchAction class to eliminate some of the "c.r.u.d" type of actions.
>  
> The problem I have is I cannot figure out how to subclass this and add in my needed functionality, because it looks like it just wants a clean action and I need (currently) to use something like a executeAction subclass method call.
>  
>  
> Does anyone have any information in regards to using this?
>  
> Thanks,
> Scott
> 


-- 
Rick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org