• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Struts MessageResources and Dependancies of Manager/Logic

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Andrew Leer
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic