Accessing message resources outside an action class
Joined: Apr 27, 2006
Hi Ranchers! I've got a question about message resources...
I would like to be able to access my message resources in a regular class, I mean, not a servlet (action) class. Is there any way to do this?
In my project, I have to send a mail when a certain action class is accessed. It's off course not a problem to access the message resources there. The actual sending of the mail and the assembling of the mail are done in seperate classes (no servlets). It's in the assembling class that I need to access the message resources.
What I could do is fetch some messages in the action class and pass them on with parameters in a method of the assembling class. But you onderstand that there would be a lot of parameters, which is not nice. Maybe passing a single hastable with all the required messages in it, is an option, but I don't like it... :-)
Is there any other way to access my message resources in the assembling class?
Thx for your help! (Would a piece of code help you guys? ;-))
SCJP 1.5, SCWCD 1.4, SCBCD 5
Joined: Feb 15, 2005
One possible way to do this would be to get the org.apache.struts.util.MessageResources object in your Action by calling the getResources(request) method obtained from the Action superclass. You could then pass the entire MessageResources object into your email generating class and then access whatever message you want in it using its getMessage() method.
If you're using internationalization in your application, you will also have to get the Locale object from the superclass getLocale() method and pass it into your email generating class as well.