GeeCON Prague 2014*
The moose likes Struts and the fly likes Struts MessageResources and Dependancies of Manager/Logic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts MessageResources and Dependancies of Manager/Logic" Watch "Struts MessageResources and Dependancies of Manager/Logic" New topic
Author

Struts MessageResources and Dependancies of Manager/Logic

Andrew Leer
Ranch Hand

Joined: Nov 11, 2003
Posts: 44
Say I'm in a struts action:
to get the list of keys from ApplicationResources.properties, I do the following:


Now I understand that if I call messageResources.get(key) I will get back the requested property from ApplicationResources.properties.


Now suppose that a little later in the action I want to pass the messageResources object I just retrieved to a Manager/Logic class, so it can retrieve a key, but without making the Manager/Logic dependent on the Struts Framework.

Would I simply retrieve the value from the messageResources and pass it into the Manager/Logic method?
(this seems a little awkward since so many values are being passed this way)

Thank you,

- Andrew J. Leer
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Actually, the method on MessageResources that gets the message is getMessage(key) or getMessage(locale, key);

I don't see any other alternatives than the ones you've already presented. Either you make your manager object dependent on Struts and pass it the MessageResources object, or you have your action class get the message first and pass it in as a string to your manager class.


Merrill
Consultant, Sima Solutions
Andrew Leer
Ranch Hand

Joined: Nov 11, 2003
Posts: 44
Well what about using a BeanUtils "Converter" implementation to convert only the necessary properties into a java.util.Properties object?

Is this feasable?

I only want to store all the messages (that relate to the same thing) in one place so I can change them throughout the entire application. (no redundancy)
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I think you're headed in the right direction. I'd use a ResourceBundle, though, instead of a Properties object. That way you still have i18n support. Just create the ResourceBundle like this:

ResourceBundle myResources = ResourceBundle.getBundle("ApplicationResources", currentLocale);

Then pass it in to your manager object. You can then use ResourceBundle'sh getString method to retrieve your messages. Since ResourceBundle is in java.util, you won't have any dependency issues.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts MessageResources and Dependancies of Manager/Logic