Refresh resource bundle from within the ADF application – to absorb changes in database backed bundles
In previous articles I discussed how resource bundles can be used for centralizing the boilerplate text items and how a resource bundle can be implemented in a database table. I also demonstrated I how to support not just different boilerplate text items for different languages but also different sets of boiler plate text for user groups that vary by location, role, department, age or personal preference. One important aspect was not discussed thus far: how to refresh the resource bundle after the application has been started. It is very nice to use a database table to store the resource bundle entries, but one of the suggested advantages is that resource bundle entries can be added and modified while the application is running and these changes would be absorbed without having to redeploy or restart the application. This article will explain how to implement that ‘refresh resource bundle while running’ option.
Steps to add the force refresh resource bundle to an ADF application with database backed resource bundles
This article continues the story that was last told in this article: http://technology.amis.nl/2012/08/13/adding-customization-or-context-sensitivity-to-boilerplate-text-from-database-backed-resource-bundles-in-adf-applications. The application discussed here is the one created in that and previous articles.
The essence of refreshing the resource bundle is also discussed in this article: http://technology.amis.nl/2006/10/14/testing-i18n-features-of-jsf-applications-forcing-a-refresh-of-the-resource-bundles/. The initial findings in this article still hold true today – except that in JDK 6 the option to refresh the cache of resource bundles was built into the JRE as intrinsic option. For Java 6 and later, the code is therefore extremely simple. For previous versions, the code is a little more elaborate.
The implementation consists of two steps. One is the creation of a commandLink that the user can activate to start the refresh. That is easy:
The second half of the implementation consists of the actionListener actionForceBundleRefresh() in the MessageManager class – and the code that this method invokes.
Initially, forceBundleRefresh attempts to use the Java 6 approach: ResourceBundle.clearCache(). That does it at the JVM level – fairly coarse grained!
More fine grained would be to retrieve all individual resource bundles by name and refresh those (and not for example touch resource bundles for other applications running on the same JVM):
When the Java 6 approach does not work, the code calls back to the ‘old fashioned’ alternative. Bundle by bundle is processed and for each bundle, the refreshBundle() method is invoked:
using some helper methods:
To see this in action. Run the application.
Now change one of the resource bundle entries displayed in the page, in the underlying database table:
make the change to this entry that is used for the button label:
Return to the page and press the refresh link:
now the bundle’s cache is emptied and when next a value is requested from the bundle it is reloaded from the database.
Download the ADF application that is discussed in this article: ADFFacesWithResourceBundle_Step5_WithForceRefresh.
Other articles in this series:
- Adding customization (or context sensitivity) to boilerplate text from database backed resource bundles in ADF applications
- Supporting multiple languages in ADF applications backed by resource bundles – and programmatically controlling the JSF locale
- Implement resource bundles for ADF applications in a database table
- Introduction to Resource Bundles in ADF applications for centralizing (management of) boilerplate text
- Testing i18n features of JSF applications – Forcing a refresh of the Resource Bundle(s)
- ADF: (Automatic) Partial Page Rendering across Taskflows
- ADF client-side architecture – Select All
- On the Integrity of Data
- ADF DVT: Analyzing Financial Position of the European Football (Soccer) Leagues using Treemap
- ADF DVT – Scaling TreeMap components for comparisons across masters and categories
- ADF DVT: Using the Tree Map visualization component – to compare relative sizes and distributions
- ADF DVT: Using the Timeline component to visualize the recent history of an RSS feed
- ADF: (re-)Introducing Contextual Events in several simple steps
- ADF DVT Speed Date: Interactive Bubble Graph
- ADF Mobile : Implementing the “Pull to Refresh” Pattern