I think this is the best way to go.

We have somethign similar...We are using struts 1.0..

And we have over ridden perform method and  added pre and processing hooks


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

                preprocess(mapping, form, request, response);

                ActionForward result = null;

                // new exception handling prepared
                ActionErrors errors = (ActionErrors) request.getAttribute(ERROR_KEY);

                if (errors == null)
                        errors = new ActionErrors();

                try {
                                //check login();
                                ActionForward forward =
                                        prePerformAction(mapping, form, errors, 
request, response);
                                if (forward != null)
                                        return forward;

                                // new exception handling prepared

                                result =
                                        performAction(mapping, form, errors, request, 
response);

                } catch (ServiceException ex) {

                } catch (Throwable t) {
                        //do error handling stuff..
                } finally {
                        handleErrors(request, errors);
                }
                return result;
        }



-----Original Message-----
From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 2:21 PM
To: Struts Users Mailing List
Subject: Re: Right way to extends Action


Hi,
In our application we use a similar concept :

- we have a class like this :
public abstract class BaseAction extends Action

In this class :

- we added some usefull field like a logger an a pointer to a singleton that
retains application's data
    protected Log log = LogFactory.getLog(this.getClass());
    protected static final Infos infos = Infos.getInstance();

- We change the modifier of the execute Method so as to be sure nobody use
it directly:
    public final ActionForward execute(ActionMapping _mapping, ActionForm
_form, HttpServletRequest _req, HttpServletResponse _res) throws Exception {

- In this method we check the user session and log in information
- At the end of this method we call
    return executeAction(_mapping, _form, _req, _res);

- This method "executeAction" is defined as this :
    public abstract ActionForward executeAction(ActionMapping _mapping,
ActionForm _form, HttpServletRequest _req, HttpServletResponse _res) throws
Exception;

- So when we create a new action, we extend BaseAction and implement the
abstract method executeAction
This way, we have automatic user login check, and a logger at disposition.

regards,

Xavier

----- Original Message -----
From: "niksa_os" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Monday, March 31, 2003 1:45 PM
Subject: Right way to extends Action


I want all my Actions to extend BaseAction.

In BaseAction I want to check user session and to put some data in it, if
that data doesn't exist.

Is it good way:

public class SomeAction extends BaseAction {
  public ActionForward execute( ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response ) {
  super.execute( mapping,form, request, response);
  OK, proceed ...........


public class BaseAction extends BaseAction {
  public ActionForward execute( ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response ) {
  if (userSession is wrong) {
    -try   -- put data in session
    -catch -- return mapping.findForward("wrongSession");}
  else return null;  //everything is OK

What you think about this way and is there better way to extend Action?

Thanks.



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


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

Reply via email to