Hi folks,
I am using Tiles with Struts 1.2.9. I have a 'standard' JSP defining
the global layout used by all pages, as in the snippets below:
#####
* File: /WEB-INF/tiles-defs.xml
<tiles-definitions>
<definition name="standard" path="/WEB-INF/tiles/standard.jsp">
<put name="jsphead" content="/WEB-INF/tiles/standard/jsphead.jsp"/>
<put name="htmlhead" content="/WEB-INF/tiles/standard/htmlhead.jsp"/>
<put name="title" content="/WEB-INF/tiles/standard/title.jsp"/>
<put name="content" content="/WEB-INF/tiles/standard/content.jsp"/>
<put name="footer" content="/WEB-INF/tiles/standard/footer.jsp"/>
</definition>
<definition name="default" extends="standard">
<put name="content" content="/WEB-INF/tiles/default/content.jsp"/>
</definition>
<!-- Other definitions extending standard... -->
</tiles-definition>
#####
* File: /WEB-INF/tiles/standard.jsp
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version=" 1.2"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:html="/tags/struts-html"
xmlns:bean="/tags/struts-bean"
xmlns:tiles="/tags/struts-tiles">
<tiles:insert attribute="jsphead" />
<html:html xhtml="false">
<tiles:insert attribute="htmlhead" />
<body>
<tiles:insert attribute="title" />
<tiles:insert attribute="content" />
<tiles:insert attribute="footer" />
</body>
</html:html>
</jsp:root>
#####
Now, I would like to have a definition that extends 'standard' while
defining new entry points. I have tried using the following approach:
#####
* File: /WEB-INF/tiles-defs.xml
<definition name="multiPane" extends="standard">
<put name="content" content="/WEB-INF/tiles/multiPane/content.jsp"/>
<putList name="pgList">
<add value="/WEB-INF/tiles/multiPane/blank.jsp"/>
</putList>
</definition>
<definition name="test" extends="multiPane">
<putList name="pgList">
<add value="/WEB-INF/tiles/test/page1.jsp"/>
<add value="/WEB-INF/tiles/test/page2.jsp"/>
</putList>
</definition>
File: /WEB-INF/tiles/multiPane/content.jsp
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="1.2"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:html="/tags/struts-html"
xmlns:tiles="/tags/struts-tiles"
xmlns:logic="/tags/struts-logic"
xmlns:bean="/tags/struts-bean">
<html:xhtml/>
<div id="content">
<tiles:useAttribute name="pgList" id="pgList" classname="
java.util.List"/>
<logic:iterate name="pgList" id="pg">
<tiles:insert flush="false">
<jsp:attribute name="page"><bean:write name="pg"/></jsp:attribute>
</tiles:insert>
</logic:iterate>
</div>
</jsp:root>
#####
* File: /test/index.jsp
<%@(protected)" %>
<%@(protected)" %>
<tiles:insert definition="test"/>
#####
In my understanding of how Tiles work, this should insert into the
index.jsp page the result of the evaluation of content.jsp, iterating
through the list provided in the tiles-defs.xml to output each tab's
content.
However, when running the above code, I end up with the following trace:
#####
javax.servlet.jsp.JspException: Error - tag useAttribute : attribute
'pgList' not found in context. Check tag syntax
at
org.apache.struts.taglib.tiles.UseAttributeTag.doStartTag (
UseAttributeTag.java:182)
at org.apache.jsp.WEB_002dINF.tiles.multiPane.content_jsp._jspService(content_jsp.java:83)
at
org.apache.jasper.runtime.HttpJspBase.service (
HttpJspBase.java:97)
at
javax.servlet.http.HttpServlet.service (
HttpServlet.java:802)
at
org.apache.jasper.servlet.JspServletWrapper.service (
JspServletWrapper.java:334)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile (
JspServlet.java:314)
at
org.apache.jasper.servlet.JspServlet.service (
JspServlet.java:264)
at
javax.servlet.http.HttpServlet.service (
HttpServlet.java:802)
...
#####
What am I doing wrong here ? Is there a way to get this working ? For
the moment, the only way I have to get the expected result, is having
every page define the raw list in its 'content' tile using
<tiles:insert page="..."/> , which induces heavily duplicated code.
Thanks in advance,
J.B Lièvremont