RE: Right way to extends Action

2003-04-01 Thread Van Riper, Mike
 -Original Message-
 From: V. Cekvenich [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 31, 2003 5:58 PM
 To: [EMAIL PROTECTED]
 Subject: Re: Right way to extends Action
  
  What about DispatchAction and LookupDispatchAction? Anyone 
 have a good
  solution for reuse of common action logic across these 
 multiple action base
  classes provided by Struts?
  
 
 
 I wrote my own dispatch:
 
 http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/
 WEB-INF/src/war/org/apache/scaffoldingLib/base/BaseAct.java
 
 .V

I think this is the strategy I will be going with myself. Since we have the
source of these helper actions, I think it is cleaner to have common action
logic in one base action class of my own and then extend all my application
actions from this one base action class. I'm good at cut/paste. So, it is
easy to create my own versions from Struts sources for the helper classes
that extend from my own base action class. :-)

Still, that means I need to track changes made in these helper actions as
Struts improves over time. I would hate to miss out on any
refinements/improvements made over subsequent releases. Which is why I was
wondering if there was a better way that I am missing.

- Van [EMAIL PROTECTED]

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



Re: Right way to extends Action

2003-03-31 Thread Xavier Saint-Denis
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]



RE: Right way to extends Action

2003-03-31 Thread shirishchandra.sakhare
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]



RE: Right way to extends Action

2003-03-31 Thread Dario Geier
I would change the signature of the executeAction method not to throw Exception, but a 
custom ActionException. This way, you would be able to be aware of what exceptions are 
thrown in your action code.

i.e. 

public abstract ActionForward executeAction(ActionMapping _mapping,
ActionForm _form, 
HttpServletRequest _req, 
HttpServletResponse _res) throws 
MyActionException;


-Original Message-
From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 3: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]



RE: Right way to extends Action

2003-03-31 Thread Kris Schneider
If you're using a Servlet 2.3 container, then filters seem like a better way to
go. Otherwise, for Struts 1.1, a custom RequestProcessor seems more appropriate.

Quoting Dario Geier [EMAIL PROTECTED]:

 I would change the signature of the executeAction method not to throw
 Exception, but a custom ActionException. This way, you would be able to be
 aware of what exceptions are thrown in your action code.
 
 i.e. 
 
 public abstract ActionForward executeAction(  ActionMapping _mapping,
   ActionForm _form, 
   HttpServletRequest _req, 
   HttpServletResponse _res) throws 
 MyActionException;
 
 
 -Original Message-
 From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 31, 2003 3: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]
 


-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

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



Re: Right way to extends Action

2003-03-31 Thread Xavier Saint-Denis
Hi,

Why have we choose to raise  Execption on our BaseAction ?

Because, as was designed the execute method of the Action class, the
exceptions raised in an action class are passed back to the ActionSevlet,
who can handle all the exceptions that we have defined in the Struts config
file.

Xavier

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 2:41 PM
Subject: RE: Right way to extends Action


I would change the signature of the executeAction method not to throw
Exception, but a custom ActionException. This way, you would be able to be
aware of what exceptions are thrown in your action code.

i.e.

public abstract ActionForward executeAction( ActionMapping _mapping,
ActionForm _form,
HttpServletRequest _req,
HttpServletResponse _res) throws MyActionException;


-Original Message-
From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 3: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]





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



RE: Right way to extends Action

2003-03-31 Thread Dario Geier
Ho Xavier,

so, how do you know which exception are thrown? You'll discover them at runtime :(

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


Hi,

Why have we choose to raise  Execption on our BaseAction ?

Because, as was designed the execute method of the Action class, the
exceptions raised in an action class are passed back to the ActionSevlet,
who can handle all the exceptions that we have defined in the Struts config
file.

Xavier

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 2:41 PM
Subject: RE: Right way to extends Action


I would change the signature of the executeAction method not to throw
Exception, but a custom ActionException. This way, you would be able to be
aware of what exceptions are thrown in your action code.

i.e.

public abstract ActionForward executeAction( ActionMapping _mapping,
ActionForm _form,
HttpServletRequest _req,
HttpServletResponse _res) throws MyActionException;


-Original Message-
From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 3: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]





-
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]



Re: Right way to extends Action

2003-03-31 Thread Xavier Saint-Denis
Hum...

To my modest opinion, this is how Struts is designed.

The execute method of the Action class raise Exception.

For exemple when I implement an action that can raise an
IdentificationException, I have to register an ExceptionHandler for this
exception in the corresponding action

Here is 2 extracts from the struts-config_1_1.dtd concerning this point :

!ELEMENT action (icon?, display-name?, description?, set-property*,
exception*, forward*)

And the comment about execption :

!-- The exception element registers an ExceptionHandler for an exception
type.
 The following attributes are defined:

bundle   Servlet context attribute for the message resources
bundle
 associated with this handler. The default attribute is
the
 value specified by the string constant declared at
 Globals.MESSAGES_KEY.
 [org.apache.struts.Globals.MESSAGES_KEY]

classNameThe configuration bean for this ExceptionHandler
object.
 If specified, className must be a subclass of the
default
 configuration bean
 [org.apache.struts.config.ExceptionConfig]

handler  Fully qualified Java class name for this exception
handler.
 [org.apache.struts.action.ExceptionHandler]

key  The key to use with this handler's message resource
bundle
 that will retrieve the error message template for this
 exception.

path The module-relative URI to the resource that will
complete
 the request/response if this exception occurs.

scopeThe context (request or session) that is used to
access
 the ActionError object
[org.apache.struts.action.ActionError]
 for this exception.

type Fully qualified Java class name of the exception type
to
 register with this handler.
--

regards

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 4:41 PM
Subject: RE: Right way to extends Action


Ho Xavier,

so, how do you know which exception are thrown? You'll discover them at
runtime :(

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


Hi,

Why have we choose to raise  Execption on our BaseAction ?

Because, as was designed the execute method of the Action class, the
exceptions raised in an action class are passed back to the ActionSevlet,
who can handle all the exceptions that we have defined in the Struts config
file.

Xavier

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 2:41 PM
Subject: RE: Right way to extends Action


I would change the signature of the executeAction method not to throw
Exception, but a custom ActionException. This way, you would be able to be
aware of what exceptions are thrown in your action code.

i.e.

public abstract ActionForward executeAction( ActionMapping _mapping,
ActionForm _form,
HttpServletRequest _req,
HttpServletResponse _res) throws MyActionException;


-Original Message-
From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 3: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

RE: Right way to extends Action

2003-03-31 Thread Dario Geier
Yes, I know that, but still, and this is a true question.
If you throw java.lang.Exception on your executeAction, then, how do you know which 
exceptions to declare in the config.xml?


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


Hum...

To my modest opinion, this is how Struts is designed.

The execute method of the Action class raise Exception.

For exemple when I implement an action that can raise an
IdentificationException, I have to register an ExceptionHandler for this
exception in the corresponding action

Here is 2 extracts from the struts-config_1_1.dtd concerning this point :

!ELEMENT action (icon?, display-name?, description?, set-property*,
exception*, forward*)

And the comment about execption :

!-- The exception element registers an ExceptionHandler for an exception
type.
 The following attributes are defined:

bundle   Servlet context attribute for the message resources
bundle
 associated with this handler. The default attribute is
the
 value specified by the string constant declared at
 Globals.MESSAGES_KEY.
 [org.apache.struts.Globals.MESSAGES_KEY]

classNameThe configuration bean for this ExceptionHandler
object.
 If specified, className must be a subclass of the
default
 configuration bean
 [org.apache.struts.config.ExceptionConfig]

handler  Fully qualified Java class name for this exception
handler.
 [org.apache.struts.action.ExceptionHandler]

key  The key to use with this handler's message resource
bundle
 that will retrieve the error message template for this
 exception.

path The module-relative URI to the resource that will
complete
 the request/response if this exception occurs.

scopeThe context (request or session) that is used to
access
 the ActionError object
[org.apache.struts.action.ActionError]
 for this exception.

type Fully qualified Java class name of the exception type
to
 register with this handler.
--

regards

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 4:41 PM
Subject: RE: Right way to extends Action


Ho Xavier,

so, how do you know which exception are thrown? You'll discover them at
runtime :(

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


Hi,

Why have we choose to raise  Execption on our BaseAction ?

Because, as was designed the execute method of the Action class, the
exceptions raised in an action class are passed back to the ActionSevlet,
who can handle all the exceptions that we have defined in the Struts config
file.

Xavier

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 2:41 PM
Subject: RE: Right way to extends Action


I would change the signature of the executeAction method not to throw
Exception, but a custom ActionException. This way, you would be able to be
aware of what exceptions are thrown in your action code.

i.e.

public abstract ActionForward executeAction( ActionMapping _mapping,
ActionForm _form,
HttpServletRequest _req,
HttpServletResponse _res) throws MyActionException;


-Original Message-
From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 3: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

Re: Right way to extends Action

2003-03-31 Thread Xavier Saint-Denis
For example, in my BaseAction class, when we verify that the user is logged
in :
if this is not the case, = throw new IdentificationException();

In the Struts config file (or locally to the action)  we add :

global-exceptions
exception
type=com.aaa.common.indentification.IdentificationException
path=/login.do key=error.identification.notlogin/
/global-exception

When the IdentificationException is raised it is always intercepted by the
ActionServlet because it throws Exception.
And this is the ActionServlet job to find if a matching exception
declaration is present in the config file so as to redirect the response
accordingly.

Regards,

Xavier


- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 5:32 PM
Subject: RE: Right way to extends Action


Yes, I know that, but still, and this is a true question.
If you throw java.lang.Exception on your executeAction, then, how do you
know which exceptions to declare in the config.xml?


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


Hum...

To my modest opinion, this is how Struts is designed.

The execute method of the Action class raise Exception.

For exemple when I implement an action that can raise an
IdentificationException, I have to register an ExceptionHandler for this
exception in the corresponding action

Here is 2 extracts from the struts-config_1_1.dtd concerning this point :

!ELEMENT action (icon?, display-name?, description?, set-property*,
exception*, forward*)

And the comment about execption :

!-- The exception element registers an ExceptionHandler for an exception
type.
 The following attributes are defined:

bundle   Servlet context attribute for the message resources
bundle
 associated with this handler. The default attribute is
the
 value specified by the string constant declared at
 Globals.MESSAGES_KEY.
 [org.apache.struts.Globals.MESSAGES_KEY]

classNameThe configuration bean for this ExceptionHandler
object.
 If specified, className must be a subclass of the
default
 configuration bean
 [org.apache.struts.config.ExceptionConfig]

handler  Fully qualified Java class name for this exception
handler.
 [org.apache.struts.action.ExceptionHandler]

key  The key to use with this handler's message resource
bundle
 that will retrieve the error message template for this
 exception.

path The module-relative URI to the resource that will
complete
 the request/response if this exception occurs.

scopeThe context (request or session) that is used to
access
 the ActionError object
[org.apache.struts.action.ActionError]
 for this exception.

type Fully qualified Java class name of the exception type
to
 register with this handler.
--

regards

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 4:41 PM
Subject: RE: Right way to extends Action


Ho Xavier,

so, how do you know which exception are thrown? You'll discover them at
runtime :(

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


Hi,

Why have we choose to raise  Execption on our BaseAction ?

Because, as was designed the execute method of the Action class, the
exceptions raised in an action class are passed back to the ActionSevlet,
who can handle all the exceptions that we have defined in the Struts config
file.

Xavier

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 2:41 PM
Subject: RE: Right way to extends Action


I would change the signature of the executeAction method not to throw
Exception, but a custom ActionException. This way, you would be able to be
aware of what exceptions are thrown in your action code.

i.e.

public abstract ActionForward executeAction( ActionMapping _mapping,
ActionForm _form,
HttpServletRequest _req,
HttpServletResponse _res) throws MyActionException;


-Original Message-
From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 3: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

RE: Right way to extends Action

2003-03-31 Thread Dario Geier
Ok, but still.how do you know about all the exceptions thrown by libraries or APIs 
you use? Part or most of them you'll reallize just on runtime

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


For example, in my BaseAction class, when we verify that the user is logged
in :
if this is not the case, = throw new IdentificationException();

In the Struts config file (or locally to the action)  we add :

global-exceptions
exception
type=com.aaa.common.indentification.IdentificationException
path=/login.do key=error.identification.notlogin/
/global-exception

When the IdentificationException is raised it is always intercepted by the
ActionServlet because it throws Exception.
And this is the ActionServlet job to find if a matching exception
declaration is present in the config file so as to redirect the response
accordingly.

Regards,

Xavier


- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 5:32 PM
Subject: RE: Right way to extends Action


Yes, I know that, but still, and this is a true question.
If you throw java.lang.Exception on your executeAction, then, how do you
know which exceptions to declare in the config.xml?


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


Hum...

To my modest opinion, this is how Struts is designed.

The execute method of the Action class raise Exception.

For exemple when I implement an action that can raise an
IdentificationException, I have to register an ExceptionHandler for this
exception in the corresponding action

Here is 2 extracts from the struts-config_1_1.dtd concerning this point :

!ELEMENT action (icon?, display-name?, description?, set-property*,
exception*, forward*)

And the comment about execption :

!-- The exception element registers an ExceptionHandler for an exception
type.
 The following attributes are defined:

bundle   Servlet context attribute for the message resources
bundle
 associated with this handler. The default attribute is
the
 value specified by the string constant declared at
 Globals.MESSAGES_KEY.
 [org.apache.struts.Globals.MESSAGES_KEY]

classNameThe configuration bean for this ExceptionHandler
object.
 If specified, className must be a subclass of the
default
 configuration bean
 [org.apache.struts.config.ExceptionConfig]

handler  Fully qualified Java class name for this exception
handler.
 [org.apache.struts.action.ExceptionHandler]

key  The key to use with this handler's message resource
bundle
 that will retrieve the error message template for this
 exception.

path The module-relative URI to the resource that will
complete
 the request/response if this exception occurs.

scopeThe context (request or session) that is used to
access
 the ActionError object
[org.apache.struts.action.ActionError]
 for this exception.

type Fully qualified Java class name of the exception type
to
 register with this handler.
--

regards

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 4:41 PM
Subject: RE: Right way to extends Action


Ho Xavier,

so, how do you know which exception are thrown? You'll discover them at
runtime :(

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


Hi,

Why have we choose to raise  Execption on our BaseAction ?

Because, as was designed the execute method of the Action class, the
exceptions raised in an action class are passed back to the ActionSevlet,
who can handle all the exceptions that we have defined in the Struts config
file.

Xavier

- Original Message -
From: Dario Geier [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Monday, March 31, 2003 2:41 PM
Subject: RE: Right way to extends Action


I would change the signature of the executeAction method not to throw
Exception, but a custom ActionException. This way, you would be able to be
aware of what exceptions are thrown in your action code.

i.e.

public abstract ActionForward executeAction( ActionMapping _mapping,
ActionForm _form,
HttpServletRequest _req,
HttpServletResponse _res) throws MyActionException;


-Original Message-
From

RE: Right way to extends Action

2003-03-31 Thread Van Riper, Mike
 -Original Message-
 From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 31, 2003 4:21 AM
 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

What about DispatchAction and LookupDispatchAction? Anyone have a good
solution for reuse of common action logic across these multiple action base
classes provided by Struts?

 
 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]



Re: Right way to extends Action

2003-03-31 Thread Igor Shabalov
	In general I like an idea to assembly application from set of pre-defined 
actions with parameters. It is about reuse of actual action 
implementations within application.
	Best,
	Igor.

On Mon, 31 Mar 2003 17:07:09 -0800, Van Riper, Mike 
[EMAIL PROTECTED] wrote:

-Original Message-
From: Xavier Saint-Denis [mailto:[EMAIL PROTECTED]
Sent: Monday, March 31, 2003 4:21 AM
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
What about DispatchAction and LookupDispatchAction? Anyone have a good
solution for reuse of common action logic across these multiple action 
base
classes provided by Struts?

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]



--
Igor Shabalov
Director of Engineering
Exadel Inc.
http://www.exadel.com
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Right way to extends Action

2003-03-31 Thread V. Cekvenich

- 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();
Be aware that adding other properties to Action is not thread safe.

.V



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


Re: Right way to extends Action

2003-03-31 Thread V. Cekvenich



What about DispatchAction and LookupDispatchAction? Anyone have a good
solution for reuse of common action logic across these multiple action base
classes provided by Struts?


I wrote my own dispatch:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/WEB-INF/src/war/org/apache/scaffoldingLib/base/BaseAct.java

.V



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


Re: Right way to extends Action

2003-03-31 Thread Navjot Singh
thanks buddy, got the idea now. My problem is solved.
-navjot

The programming world now seems to be all about writing wrapper codes ;-)


- Original Message -
From: V. Cekvenich [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, April 01, 2003 7:27 AM
Subject: Re: Right way to extends Action


|
| 
| 
|  What about DispatchAction and LookupDispatchAction? Anyone have a good
|  solution for reuse of common action logic across these multiple action
base
|  classes provided by Struts?
| 
|
|
| I wrote my own dispatch:
|
|
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/basicportal/bP/WEB-INF/src/wa
r/org/apache/scaffoldingLib/base/BaseAct.java
|
| .V
|
|
|
|
| -
| 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]