You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/08/26 23:15:50 UTC

What if you need all your dispatchAction methods to call a common method?

Before I get yelled at for handling if a user logged in by the
application and not by the container, let me first explain it's not my
first choice to do it this way... it's a long story but just wanted to
set that out before I get e-mails about not having the struts
application deal with a user being logged in.

All my actions funnel through one DispatchAction class. The question I
have is "Is there a way to have all of the methods in this action call
some other common method before they perform their own action related
stuff?" To be specific in this case, I need to make sure a bean stored
in their session hasn't become null if their session has expired
before continuing on with the action method. If the session bean is
null I want to redirect them back to the login page with the message
"Session has timed out."

Is there a way that a DispatchAction will always call some other
method first where I can place some generic code that all the
dispatchAction methods will thus execute? Otherwise I guess I have to
check for the state of the bean in the session in every single
dispatchAction method.

Thanks for any ideas.



-- 

Rick
mailto:maillist@reumann.net


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: What if you need all your dispatchAction methods to call a common method?

Posted by John Yu <jo...@scioworks.com>.
Does overriding the execute()/perform() method in the DispatchAction do the 
work?

   public class YourDispatchAction extends DispatchAction {
     public Forward execute(...) throws Exception {
       preExecute(...);
       return super.execute(...);
     }
     abstract public void preExecute();
   }


At 05:15 am 27-08-2002, you wrote:
>Before I get yelled at for handling if a user logged in by the
>application and not by the container, let me first explain it's not my
>first choice to do it this way... it's a long story but just wanted to
>set that out before I get e-mails about not having the struts
>application deal with a user being logged in.
>
>All my actions funnel through one DispatchAction class. The question I
>have is "Is there a way to have all of the methods in this action call
>some other common method before they perform their own action related
>stuff?" To be specific in this case, I need to make sure a bean stored
>in their session hasn't become null if their session has expired
>before continuing on with the action method. If the session bean is
>null I want to redirect them back to the login page with the message
>"Session has timed out."
>
>Is there a way that a DispatchAction will always call some other
>method first where I can place some generic code that all the
>dispatchAction methods will thus execute? Otherwise I guess I have to
>check for the state of the bean in the session in every single
>dispatchAction method.
>
>Thanks for any ideas.
>--
>Rick

-- 
John Yu                       Scioworks Technologies
e: john@scioworks.com         w: +(65) 873 5989
w: http://www.scioworks.com   m: +(65) 9782 9610

Scioworks Camino - "Don't develop Struts Apps without it!"


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: What if you need all your dispatchAction methods to call a common method?

Posted by mike m <st...@wryse.com>.
Rick,
You can make an abstract base action with an abstract method that is always
called.  Check out this previous post; it's the same idea.
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg37313.html
Mike

-----Original Message-----
From: Rick Reumann [mailto:maillist@reumann.net]
Sent: Monday, August 26, 2002 5:16 PM
To: Struts List
Subject: What if you need all your dispatchAction methods to call a
common method?


Before I get yelled at for handling if a user logged in by the
application and not by the container, let me first explain it's not my
first choice to do it this way... it's a long story but just wanted to
set that out before I get e-mails about not having the struts
application deal with a user being logged in.

All my actions funnel through one DispatchAction class. The question I
have is "Is there a way to have all of the methods in this action call
some other common method before they perform their own action related
stuff?" To be specific in this case, I need to make sure a bean stored
in their session hasn't become null if their session has expired
before continuing on with the action method. If the session bean is
null I want to redirect them back to the login page with the message
"Session has timed out."

Is there a way that a DispatchAction will always call some other
method first where I can place some generic code that all the
dispatchAction methods will thus execute? Otherwise I guess I have to
check for the state of the bean in the session in every single
dispatchAction method.

Thanks for any ideas.



--

Rick
mailto:maillist@reumann.net


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>