Hi,
Is there any way to flush the message resources cache?
My requirement is to be able to dynamically edit labels
without bouncing the servlet container. I have my own
MessageResources implementation that connects to our
own dictionary which is loaded from the db. So the
problem is that even though I have changed a value associated
with a key and it is persisted to the db, the new call
never gets made due to the caching in the method below. I am using
the struts 1.0 release.
Right now I am thinking the only solution is to subclass ActionServlet,
and then provide a public wrapper for the initApplication() method, so
that I can call it from an action class, but I just want to make sure there
isn't an easier way, as I have been avoiding subclassing the ActionServlet
for a few months now ;)
thanks,
dan
public String getMessage(Locale locale, String key, Object args[]) {
// Cache MessageFormat instances as they are accessed
if (locale == null)
locale = defaultLocale;
MessageFormat format = null;
String formatKey = messageKey(locale, key);
synchronized (formats) {
format = (MessageFormat) formats.get(formatKey);
if (format == null) {
String formatString = getMessage(locale, key);
if (formatString == null) {
if (returnNull)
return (null);
else
return ("???" + formatKey + "???");
}
format = new MessageFormat(formatString);
formats.put(formatKey, format);
}
}
return (format.format(args));
}