Re: 'Module scoped' variables
On Dec 10, 2003, at 10:47 AM, Fullam, Jonathan wrote: Yes. I actually thought of that issue after I replied to you. Another option you can look into is subclassing the ControllerConfig class and specify your new Config class in the className attribute of the controller element in each of your modules. You could then build in the functionality to configure extra "module-scoped" variable. I think you could do it more simply. In org.apache.struts.util.RequestUtils, there's this method: public static String getModuleName(HttpServletRequest request, ServletContext context) { return ModuleUtils.getInstance().getModuleName(request, context); } So now, in any situation where you have a request and a servlet context, you can look up the current module name. Using this, you can construct unique names for things stored in the application (servlet) context. This is what Struts does, of course. Depending on what's easiest for you, you can locate this expertise anyplace. The simplest would probably be in a method in a subclass of org.apache.struts.action.Action which you would then subclass for all of your application methods. Then write a couple of methods like public Object getModuleAttribute(HttpServletRequest request, String name) public void setModuleAttribute(HttpServletRequest request, String name, Object attr) and inside those methods, use RequestUtils to lookup the module name, and then lookup a java.util.Map under a "well-known name" like {module}/MODULE_CONTEXT_MAP and... there you have it. It's a little bit oblique, but then Modules were kind of retrofitted into the Struts structure. This could probably be made easier in future releases if people had ideas, or even better, patches to the source code! Joe -- Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "We want beef in dessert if we can get it there." -- Betty Hogan, Director of New Product Development, National Cattlemen's Beef Association smime.p7s Description: S/MIME cryptographic signature
RE: 'Module scoped' variables
Yes. I actually thought of that issue after I replied to you. Another option you can look into is subclassing the ControllerConfig class and specify your new Config class in the className attribute of the controller element in each of your modules. You could then build in the functionality to configure extra "module-scoped" variable. -Jonathan -Original Message- From: Lawrence Williams [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 11:35 AM To: Struts Users Mailing List Subject: RE: 'Module scoped' variables Thanks Jonathan, That's kind of the half solution I have at present - the problem is I have to specify the parameter in all my actions as it is 'global to the module'. This makes changing the value a bit tedious. Does this make sense? Regards Lawrence -Original Message- From: Fullam, Jonathan [mailto:[EMAIL PROTECTED] Sent: 10 December 2003 16:23 To: 'Struts Users Mailing List' Subject: RE: 'Module scoped' variables Not sure if it's exactly what you want but I know you can use the parameter attribute of the action tags to specify a value that is accessible using mapping.getParameter() from withing you Action class. -Jonathan -Original Message- From: Lawrence Williams [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 11:20 AM To: [EMAIL PROTECTED] Subject: 'Module scoped' variables Hi, Hope this isn't too naïve a question Is there anyway of setting parameters in a module-level struts-config file and referencing those variables within an action? Effectively giving me a module scope. Regards Lawrence --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: 'Module scoped' variables
Thanks Jonathan, That's kind of the half solution I have at present - the problem is I have to specify the parameter in all my actions as it is 'global to the module'. This makes changing the value a bit tedious. Does this make sense? Regards Lawrence -Original Message- From: Fullam, Jonathan [mailto:[EMAIL PROTECTED] Sent: 10 December 2003 16:23 To: 'Struts Users Mailing List' Subject: RE: 'Module scoped' variables Not sure if it's exactly what you want but I know you can use the parameter attribute of the action tags to specify a value that is accessible using mapping.getParameter() from withing you Action class. -Jonathan -Original Message- From: Lawrence Williams [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 11:20 AM To: [EMAIL PROTECTED] Subject: 'Module scoped' variables Hi, Hope this isn't too naïve a question Is there anyway of setting parameters in a module-level struts-config file and referencing those variables within an action? Effectively giving me a module scope. Regards Lawrence --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: 'Module scoped' variables
Not sure if it's exactly what you want but I know you can use the parameter attribute of the action tags to specify a value that is accessible using mapping.getParameter() from withing you Action class. -Jonathan -Original Message- From: Lawrence Williams [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 10, 2003 11:20 AM To: [EMAIL PROTECTED] Subject: 'Module scoped' variables Hi, Hope this isn't too naïve a question Is there anyway of setting parameters in a module-level struts-config file and referencing those variables within an action? Effectively giving me a module scope. Regards Lawrence --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.547 / Virus Database: 340 - Release Date: 02/12/2003 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]