• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing message resources outside an action class

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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? ;-))
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
already answered here also:

https://coderanch.com/t/54027/Struts/accessing-message-resources-processPreprocess
 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic