aspose file tools*
The moose likes Struts and the fly likes Editing Application Resources.properties  at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Editing Application Resources.properties  at runtime" Watch "Editing Application Resources.properties  at runtime" New topic
Author

Editing Application Resources.properties at runtime

Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
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
Merrill Higginson
Ranch Hand

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


Merrill
Consultant, Sima Solutions
Ayan Dutta
Ranch Hand

Joined: Oct 16, 2005
Posts: 94
Can you provide me any example how that can be done ?
Regards,
Ayan Dutta
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Editing Application Resources.properties at runtime