Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF Reload resource bundle on Glassfish 3.1.2
    primarykey
    data
    text
    <p>I want to reload/refresh my resource bundle after data updates.</p> <p>My ResourceBundle implementation is based on db, here the code:</p> <pre><code>public class DatabaseResourceBundle extends ResourceBundle { private static EntityManagerFactory factory = Persistence.createEntityManagerFactory("ADAEcommerceEjbPU"); private EntityManager _entityManager = factory.createEntityManager(); private Map&lt;String, String&gt; _values = new HashMap&lt;&gt;(); protected final static String BUNDLE_NAME = "com.infomaxgroup.adaecommerce.bundles"; private final static Logger LOGGER = Logger.getLogger(DatabaseResourceBundle.class.getName()); private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); protected Control DB_CONTROL = new DBControl(); /** * Public constructor setting the parent bundle */ public DatabaseResourceBundle() { LOGGER.log(Level.FINE, "DatabaseResourceBundle()"); setParent(ResourceBundle.getBundle(BUNDLE_NAME, FacesContext.getCurrentInstance().getViewRoot().getLocale(), DB_CONTROL)); } public DatabaseResourceBundle(Locale locale) { LOGGER.log(Level.FINE, "DatabaseResourceBundle(Locale locale)"); setParent(ResourceBundle.getBundle(BUNDLE_NAME, locale, DB_CONTROL)); } @Override protected Object handleGetObject(String key) { LOGGER.log(Level.FINE, "handleGetObject() Locale {0} Key: {1} ", new Object[]{locale.toString(), key}); return _values != null ? _values.get(key) : parent.getObject(key); } @Override public Enumeration&lt;String&gt; getKeys() { LOGGER.log(Level.FINE, "getKeys() Parent Locale {0} ", parent.getLocale()); return parent.getKeys(); } /** * The Control Callback. * * @see * http://docs.oracle.com/javase/6/docs/api/java/util/ResourceBundle.Control.html */ protected class DBControl extends Control { @Override public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { LOGGER.log(Level.INFO, "reload {0} ", reload); return new MyResources(locale); } /** * A simple ListResourceBundle */ protected class MyResources extends ListResourceBundle { private Locale locale; /** * ResourceBundle constructor with locale * * @param locale */ public MyResources(Locale locale) { this.locale = locale; } @Override protected Object[][] getContents() { if (locale == null) { locale = Locale.ITALY; } TypedQuery&lt;ResourceEntity&gt; query = _entityManager.createNamedQuery("ResourceEntity.findForLocale", ResourceEntity.class); query.setParameter("locale", locale.getLanguage()); List&lt;ResourceEntity&gt; resources = query.getResultList(); Object[][] all = new Object[resources.size()][2]; int i = 0; for (Iterator&lt;ResourceEntity&gt; it = resources.iterator(); it.hasNext();) { ResourceEntity resource = it.next(); all[i] = new Object[]{resource.getKey(), resource.getValue()}; _values.put(resource.getKey(), resource.getValue()); i++; } return all; } } } } </code></pre> <p>When I update the data and call DatabaseResourceBundle.clearCache() I see that the next request calls the method:</p> <pre><code>MyResources.getContents() </code></pre> <p>If I debug what data is returned into </p> <pre><code>Object[][] all </code></pre> <p>here I see the updated data but on the JSF page I still see the old data, seems like the JSF uses cached data.</p> <p>How can I see the updated data into JSF page ?</p> <p>Many thanks in advance...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload