Refresh resource bundle from within the ADF application - to absorb changes in database backed bundles image95

Refresh resource bundle from within the ADF application – to absorb changes in database backed bundles

Any web application contains boilerplate text: text that is not part of the enterprise data from web services or databases that is manipulated by the end users using the application but that is part of the application definition itself. Text that is shown as prompt, title, message, hint text and in other ways. Developers can sprinkle the boilerplate text all throughout the application, in pages, JavaScript and other code sections. But they should not do that. Changing boiler plate text is a frequent requirement from the business. Having all boilerplate text in a central location makes such changes a lot easier. Additionally, many organizations require applications to be multi-lingual: different groups of users speak different languages and want to have the application support them in their own language. That means boiler plate text is not just defined once in that central location, but once for every language the application needs to support.

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: 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: 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:

  1. Introduction to Resource Bundles in ADF applications for centralizing (management of) boilerplate text

  2. Implement resource bundles for ADF applications in a database table

  3. Supporting multiple languages in ADF applications backed by resource bundles – and programmatically controlling the JSF locale

  4. Adding customization (or context sensitivity) to boilerplate text from database backed resource bundles in ADF applications

  5. Refresh resource bundle from within the ADF application – to absorb changes in database backed bundles

  6. Live update of Resource Bundle from within running ADF application

  7. Live resource bundle entry editing in a generic way through declarative component and UI component tree manipulation

  8. Creating reusable ADF Library with generic live resource bundle editing functionality and reusing it in any ADF application


  1. Pol Reddy Palagiri March 18, 2014
  2. Mike August 14, 2012
    • Lucas Jellema August 15, 2012