Well, it does indeed seem to work. The question is whether it leaves any lingering resources uncollected, but I'm thinking it shouldn't. Here's my simple Struts Action that takes parameters for which file to reload and which resources object to reload:

public class ReloadMessageResourcesAction extends org.apache.struts.action.Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{
String propertyFileName = request.getParameter("propertyFileName");
String messageResourcesKey = request.getParameter("messageResources");


        if (messageResourcesKey == null)
            messageResourcesKey = Globals.MESSAGES_KEY;

MessageResourcesFactory factory =
MessageResourcesFactory.createFactory();
MessageResources resources = factory.createResources(propertyFileName);


        // Set brand new MessageResources object.  There doesn't appear to
        //  be any API for clearing out the old one.
        ServletContext ctx = getServlet().getServletContext();
        ctx.setAttribute(messageResourcesKey, resources);
        return mapping.findForward("next");
    }
}

Doug wrote:

Yes, I know this has been asked before, and I know it's not a base capability. However, someone posted this solution several months ago, which seems reasonable to me. Can anyone comment on whether there's any reason not to use this approach?

<http://marc.theaimsgroup.com/?l=struts-user&m=107880611624569&w=2>

<snip>
MessageResourcesFactory factory =
    MessageResourcesFactory.createFactory();
MessageResources resources =
    factoryObject.createResources(nameOfMessage);

ServletContext ctx = getServlet().getServletContext();
ctx.setAttribute(Globals.MESSAGES_KEY, resources);
</snip>

Doug

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to