Question

I am using Struts 2.3.15 and the s:optionselecttransfer tag is not working as the JavaScript does not load. I use:

<%@ taglib prefix="s" uri="/struts-tags" %>
<s:optiontransferselect ... />

which generates the following JavaScript:

<script type="text/javascript" src="/struts/optiontransferselect.js"></script>

My problem is caused because I call the Struts configurationManager.reload() method after loading some additional Struts2 XML config files that are stored in various plugins. Calling reload() kills the serving of static resources by Struts. My reload is done as follows:

ConfigurationManager configurationManager = dispatcher.getConfigurationManager();
StrutsXmlConfigurationProvider strutsXmlConfigurationProvider = 
        new StrutsXmlConfigurationProvider(strutsXMLLocation, false, getServletContext());
configurationManager.addContainerProvider(strutsXmlConfigurationProvider);
configurationManager.reload();

To solve this problem I have copied the files from org.apache.struts2.static to my server root so they are accessible and then used Roman C's code to prevent Struts serving static resources. This allows the s:optionselecttransfer tag's JavaScript to be found by the browser.

If anyone can hazard a guess as to why a reload() prevents the serving of static resources I would like to try to fix it. If there are no other ideas then I will accept Roman C's solution.

Was it helpful?

Solution

The s:head tag should be placed under the head tag.

The constant used by FilterDispatcher by default serves static content from inside its jar.

struts.serve.static=true

If you want to access it from context_path/struts then turn it off by setting to false.

struts.serve.static=false
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top