JavaRanch Home    
 
This page:         last edited 05 September 2007         What's Changed?         Edit

Reload Message Resources   

Is there a way to get Struts to reload the message resources files without restarting the server or the application?

The following solution was posted by Stefaan Huysentruyt in December of 2005:

Just subclass both PropertyMessageResources and PropertyMessageResourceFactory. Name them something like ReloadablePropertyMessageResources and ReloadablePropertyMessageResourcesFactory and configure them like this:


<message-resources 
parameter="myresources.mymessages" factory="net.minimoa.struts.util.ReloadablePropertyMessageResourcesFactory"
/>

The sources:

ReloadablePropertyMessageResources.java


import org.apache.struts.util.PropertyMessageResources;
 
public class ReloadablePropertyMessageResources extends PropertyMessageResources {
 
  public ReloadablePropertyMessageResources(ReloadablePropertyMessageResourcesFactory factory, String config) {
 
    super(factory, config);
 
  }
 
  public ReloadablePropertyMessageResources(ReloadablePropertyMessageResourcesFactory factory, String config, boolean returnNull) {
 
     super(factory, config, returnNull);
 
  }
 
  public synchronized void reload() {
 
    locales.clear();
 
    messages.clear();
 
    formats.clear();
 
 }
 
}

ReloadablePropertyMessageResourcesFactory.java


import org.apache.struts.util.MessageResources;
import org.apache.struts.util.PropertyMessageResourcesFactory;
 
public class ReloadablePropertyMessageResourcesFactory extends PropertyMessageResourcesFactory {
 
  public MessageResources createResources(String config) {
 
    return new ReloadablePropertyMessageResources(this, config, this.getReturnNull());
 
  }
 
}

Just put some statement like this in an Action:


((ReloadablePropertyMessageResources)getResources(request)).reload();

and voilą...



Return to StrutsFaq


JavaRanchContact us — Copyright © 1998-2014 Paul Wheaton