aspose file tools*
The moose likes Struts and the fly likes Accessing message resources outside an action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Accessing message resources outside an action class" Watch "Accessing message resources outside an action class" New topic
Author

Accessing message resources outside an action class

Tim Storms
Ranch Hand

Joined: Apr 27, 2006
Posts: 64
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
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Jason Berk
Ranch Hand

Joined: May 03, 2006
Posts: 41
already answered here also:

http://www.coderanch.com/t/54027/Struts/accessing-message-resources-processPreprocess
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing message resources outside an action class