You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jean-Baptiste Lièvremont <mi...@gmail.com> on 2006/12/05 15:21:22 UTC
[Tiles] Defining insert points in derived definitions
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
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="tiles" uri="/tags/struts-tiles" %>
<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
Re: [Tiles] Defining insert points in derived definitions
Posted by Antonio Petrelli <ap...@apache.org>.
See inline comments...
Jean-Baptiste Lièvremont ha scritto:
> * 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/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>
The problems is that you want to read attributes inside non-layout
pages. In your case your layout page is "standard.jsp" and you can read
attributes (i.e. using <tiles:insert attribute....>,
<tiles:useAttribute>, <tiles:importAttribute>) only in that page.
To solve your problem, use <tiles:importAttribute> to import your
attribute in request scope in "standard.jsp":
<tiles:importAttribute name="pgList" scope="request">
Then use it as a normal request-scoped bean.
HTH
Antonio
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org