• 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

Editing Application Resources.properties at runtime

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I edit ApplicationResources.properties at runtime from the action classes or JSPs ?

Say in ApplicationResources.properties there is an entry like key1=abcd I want to change it to key1=xyz ,is it possible ?
Regards,
Ayan Dutta
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's not possible without extending Struts.

The ApplicationResources.properties file is read in only once when the ActionServlet initializes and is not reloaded unless the application restarts. If you want to change this behavior, you will have write your own extensions to Struts.
 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you provide me any example how that can be done ?
Regards,
Ayan Dutta
 
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
If you want to extend Struts, the first thing you need to do is go to the Struts home page and download the source for the version you're using.

When you look at the source code, you will find that when the Struts ActionServlet initializes, an object of type org.apache.struts.util.MessageResources is created, populated, and placed into Application scope.

One suggestion for making the MessageResources re-loadable would be to copy the logic used to create the resource bundle into a method in a new class, and call the method reloadMessageResources(). You could then call this method whenever you wanted to reload the message resources after you had changed them.

Be aware that if you do this, you are going to face synchronization issues. What's going to happen if one user requests a rebuild of the resource bundle while another user is trying to access it to display a message at the same time? These types of issues are probably why the authors of Struts decided not to make the resource bundle re-loadable.

I'd suggest you take a good look at what you're trying to accomplish by making the resource bundle re-loadable and see if there isn't an easier, less obtrusive way of accomplishing the same thing.
[ June 28, 2006: Message edited by: Merrill Higginson ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic