0

I fail to reload my resource bundle class to reflect the changed translations (made my end-user) on page. Although getContent method executes and all translations as key/value fetched from database and object[][] returned from getContent method successfully. this happens after each time I clear the cache and refresh the jsf page through actionListener.

ResourceBundle.clearCache();

Also I tried to use the below and got the same result.

ResourceBundle.clearCache(Thread.currentThread().GetContextClassLoader());

Why WLS always see the old one? Am I miss something?

versions: 12.2.1.1.0 and 12.2.1.3.0

divibisan
  • 11,659
  • 11
  • 40
  • 58
Ahmed
  • 56
  • 1
  • 5

1 Answers1

0

The end user - after making the translations and contributing to the internationalization of the project, the translations are saved to the database, The process to inforce these operations are done through the following steps:

  1. Create a HashMap and load all the resource key/vale pairs in the map from the database:

    while (rs.next()) {      
        bundle.put(rs.getString(1), rs.getString(2));       
    }            
    
  2. Refresh the Bundle of your application

    SoftCache cache =
                (SoftCache)getFieldFromClass(ResourceBundle.class,
                                             "cacheList");
    synchronized (cache) {
            ArrayList myBundles = new ArrayList();
    
            Iterator keyIter = cache.keySet().iterator();
            while (keyIter.hasNext()) {
                Object key = keyIter.next();
                String name =
                    (String)getFieldFromObject(key, "searchName");
    
                if (name.startsWith(bundleName)) {
                    myBundles.add(key);
                    sLog.info("Resourcebundle " + name +
                              " will be refreshed.");
                }
            }
            cache.keySet().removeAll(myBundles);
    
  3. Getthe a String from ResourceBoundle of your application:

    for (String resourcebundle : bundleNames) {
            String bundleName =
            resourcebundle + (bundlePostfix == null ? "" : bundlePostfix);
            try {
                  bundle =  ResourceBundle.getBundle(bundleName, locale, getCurrentLoader(bundleName));
    
            } catch (MissingResourceException e) {
                // bundle with this name not found;
            }
    
            if (bundle == null)
                continue;
            try {
                message = bundle.getString(key);
                if (message != null)
                    break;
            } catch (Exception e) {
        }
    } 
    
  • Based on your solution I have two containers for translations. First is resource bundle and second is map object. Is this write way to have two objects loaded contains my translations? – Ahmed Mar 29 '18 at 06:19