Search code examples
javajspstruts2struts-tags

strut 2 s:select won't work within a jsp file


Hi I am getting an error where my s:select will work fine in the parent jsp file but when it is within another jsp file that is being called upon by the parent.jsp it doesn't seem to work anymore. I removed everything down to just these two lines and all the extra stuff around the select. Any suggestion or advice is greatly appreciated!

parent.jsp

<%@ taglib uri="/struts-tags" prefix="s" %>
<s:select label="some label"
    list="#{'01':'Dev','2':'Manager','03':'Customer'}"
    name="test"
    />    
<s:component template="child.jsp" templateDir="/pub/" theme="folder1" />

child.jsp

<%@ taglib uri="/struts-tags" prefix="s" %>
<s:select label="some label"
        list="#{'01':'Dev','2':'Manager','03':'Customer'}"
        name="test"
        />

File structure

/pub

----/folder1

--------parent.jsp <-- dropdown displays appears

--------child.jsp <--- dropdown breaks

Error message

Struts Problem Report
Struts has detected an unhandled exception: 
Messages:
Non-normalized name, starts with "/": /pub//simple/select.ftl
File:
freemarker/cache/TemplateCache.java
Line number:
914

Solution

  • From what I understand turns out it seems to be that you need to set the templateDir inside the child.jsp to the path to the template directory that it is within Struts 2 so it can find the code for s:select. This code managed to fix the issue:

    <s:set var="templateDir" value="%{'template'}" scope="page"/>