Here is a Struts 2 action that can be called to reload your Struts 2 resource properties. In the case below, my resource properties are "/classes/struts/resources.properties" and "/classes/struts/resources_pt.properties". Therefore, the resources bundle name is "struts/resources". I make changes to my resources properties file, and then I call the following action, and the resources are dynamically reloaded.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts-admin" extends="webapp-struts-default" namespace="/admin">
<action name="reloadResources" class="com.softlagos.web.struts2.admin.ReloadResourceBundleAction">
<result type="dispatcher" name="success">/jsp/admin/reloadResources.jsp</result>
</action>
</struts>
/*
* @(#) $Id: AdminAction.java 989 2008-10-29 17:44:55Z rgomes $
*/
package com.softlagos.web.struts2.admin;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.LocalizedTextUtil;
/**
* Responsible for reloading the resource bundle
*
* @author Rubens Gomes
*/
public final class ReloadResourceBundleAction extends ActionSupport
{
private static final long serialVersionUID = 1;
/**
* no-arg default constructor.
*/
public ReloadResourceBundleAction()
{
super();
}
/**
* Called to reload the resource bundle.
*
* @return struts result - see struts xml configuration file
*/
@Override
public String execute()
{
LocalizedTextUtil.clearDefaultResourceBundles();
LocalizedTextUtil.addDefaultResourceBundle("struts/resources");
LocalizedTextUtil.setReloadBundles(true);
return Action.SUCCESS;
}
}