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]
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]
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 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
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: Question about message-resources
Hi, Regarding how to manage very long Message-resources property file, you can use the following possibility : In your strust-config.xml add a : ?xml version=1.0 encoding=ISO-8859-1? !DOCTYPE struts-config PUBLIC -//Apache Software Foundation//DTD Struts Configuration 1.1//EN http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd; [ !ENTITY action-users SYSTEM action-mappings/backoffice/users.xml !ENTITY action-entite SYSTEM action-mappings/backoffice/entite.xml !ENTITY action-dynamicforms SYSTEM action-mappings/backoffice/dynamicforms.xml !ENTITY action-groupes SYSTEM action-mappings/backoffice/groupes.xml !ENTITY action-activites SYSTEM action-mappings/backoffice/activites.xml ] And in the appropriate section of the Action Mapping Definitions use the action-users; action-entite; to refer to your files. And for each of your modules (here like users.xml or groupes.xml) you have a property file. In that way it is more easily to manage the multi-lingual fonctionnalitie. each of this file are placed under /WEB-INF/conf/action-mappings/. Has this is a type of include, do not add XML header to this file. :-) Xav - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, March 25, 2003 9:25 AM Subject: Question about message-resources I am looking into struts-menu, and am confused about the extent I can use message-resources. Like: (struts-config.xml) message-resources parameter=TrackerRes/ message-resources parameter=ISOCodeRes key=ISOCodeRes/ I am creating a multi-lingual app, and am finding there are heaps of entries in my ApplicationResources.properties already, and it is going to get much worse as I have only done 2 pages and I have about 16 to go. So, can someone please explain what the above multiple message-resources definition does, and how I might leverage splitting up some of my message-resources, to make these files more manageable? = Thank You Mick Knutson Sr. Designer - Project Trust aUBS AG, Financial - Zürich Office: +41 (0)1/234.42.75 Internal: 48194 Mobile: 079.726.14.26 Visit our website at http://www.ubswarburg.com This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required please request a hard-copy version. This message is provided for informational purposes and should not be construed as a solicitation or offer to buy or sell any securities or related financial instruments. - 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]
html:option and message resource
Hi, I have the following problem : In the strust config file I declare this : !-- == Message Resources Definitions === -- message-resources parameter=ApplicationRessources null=false/ Where the promt.empty= is defined in the property file and used with no problem elsewhere in the code. in a tiles jsp, i use a an html:action like this : html:option key=prompt.empty value=/ but the message is not rendered and I wonder why...? Have you any idea why this occur ? Xav - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]