On Thu, 22 Jul 2004 07:54:25 +0200, Ephemeris Lappis <[EMAIL PROTECTED]> wrote: > I need to access some Struts objects, like forward mappings, from a session > listener, or other part of the application's code where no request is > available. Is it possible, and, if it is, what is the best way to do it ? > I found in the ServletContext attributes an object of type > org.struts.action.ForwardMappings that may be interesting, but this class > doesn't appear in the API documentation. Is it a private type ? > Thanks for your help.
If you are not using the "sub-application module" capability of Struts 1.1 or later, there is a straightforward way to gain access to all of the configuration information loaded from the struts-config.xml file. All of the information will be recorded in a tree of objects that is rooted in a single object of type "org.apache.struts.config.ModuleConfig". The module configuration object for the entire application is made available as a servlet context attribute under the key defined by the constant Globals.MODULE_KEY (literal value is "org.apache.struts.action.MODULE"). From here, you can get to all the definitions for forwards, form beans, actions, and so on. See the Javadocs for more information. One thing you will note is that the method signatures on ModuleConfig talk solely about XxxConfig objects. So, where are the ActionForward mappings stored? In Struts 1.1, the config package was created, and existing configuration objects from org.apache.struts.action were redefined there. However, for backwards compatibility, the existing configuration objects were redesigned to be subclasses of the new "config" package objects. Thus, you'll be able to (in Struts 1.1 and 1.2) cast an "org.apache.struts.config.ForwardConfig" object to an "org.apache.struts.action.ActionForward" if you need that. However, to minimize transition problems in future versions of Struts, it is recommended that you use the XxxConfig APIs whenever possible. You will still need a reference to the ServletContext to gain access to the configuration information, but that should be fairly easy to come by. Craig --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]