You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thomas Corte <Th...@knipp.de> on 2005/10/10 17:15:44 UTC

accessing MessageResources in a PlugIn?

Hi there,

I have a Struts plugin that needs to access the MessageResources of my 
Struts application (to send out some internationalized mails).
However, neither the ActionServlet nor the ModuleConfig passed to the 
PlugIn's init () method seem to grant access to the MessageResources.

I actually switched from a ServletContextListener to a PlugIn just 
because of this requirement, but now I'm stuck.

Is there a way to access them conveniently?

-- 
Thomas Corte
Thomas.Corte@knipp.de

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: accessing MessageResources in a PlugIn?

Posted by Kishore Senji <ki...@gmail.com>.
MessageResources.getMessageResources(config);
http://struts.apache.org/api/org/apache/struts/util/MessageResources.html#getMessageResources(java.lang.String)

Example Usage: MessageResources.getMessageResources("
org.apache.struts.taglib.LocalStrings");

On 10/10/05, Thomas Corte <Th...@knipp.de> wrote:
>
> Hi there,
>
> I have a Struts plugin that needs to access the MessageResources of my
> Struts application (to send out some internationalized mails).
> However, neither the ActionServlet nor the ModuleConfig passed to the
> PlugIn's init () method seem to grant access to the MessageResources.
>
> I actually switched from a ServletContextListener to a PlugIn just
> because of this requirement, but now I'm stuck.
>
> Is there a way to access them conveniently?
>
> --
> Thomas Corte
> Thomas.Corte@knipp.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: accessing MessageResources in a PlugIn?

Posted by Joe Germuska <Jo...@Germuska.com>.
At 5:15 PM +0200 10/10/05, Thomas Corte wrote:
>Hi there,
>
>I have a Struts plugin that needs to access the MessageResources of 
>my Struts application (to send out some internationalized mails).
>However, neither the ActionServlet nor the ModuleConfig passed to 
>the PlugIn's init () method seem to grant access to the 
>MessageResources.
>
>I actually switched from a ServletContextListener to a PlugIn just 
>because of this requirement, but now I'm stuck.

The MessageResources objects are just placed in the ServletContext, 
so if you know the attribute naming conventions, you can retrieve 
them from either a plugin or a listener.  If you use multiple modules 
in your app, you'll want to use the plugin so it can know in which 
module it has been initialized, because the module name is used to 
ensure a unique name in the servlet context.

See protected void initModuleMessageResources(ModuleConfig config) in 
ActionServlet for the real deal:
https://svn.apache.org/repos/asf/struts/core/trunk/src/java/org/apache/struts/action/ActionServlet.java

The general intention in relatively near-term development is to steer 
Struts towards using objects which mediate access to the servlet 
context so as to protect users from having to know things like this, 
but it will be a little tricky because there may be much existing 
code which depends on the current behavior.   In Struts 1.3 the 
ActionContext class provides this mediation for access to the request 
and session, so the next step is to provide it for the module and 
application level.

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"Narrow minds are weapons made for mass destruction"  -The Ex

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org