A very similar question was asked earlier this week. Check the archives for more.

Here's how I've done it, but it's not extremely elegant:

tiles-defs.xml
<!-- main layout -->
<definition name="main.layout" path="/mainlayout.jsp">
  <put name="title" value="Title" />
  <put name="header" value="/header.jsp" />
  <put name="footer" value="/footer.jsp" />
</definition>

<definition name="somepage" extends="main.layout">
  <put name="title" value="Sample Page Title" />
</definition>

Here's a snippet from mainlayout.jsp:
  <tiles:useAttribute name="title"/>
  <tiles:insert attribute="header">
    <tiles:put name="title" value="${title}" direct="false"/>
  </tiles:insert>

and here's header.jsp:
<h1>Header</h1>
<h2>Title is: <tiles:getAsString name="title"/></h2>

The problem is that header.jsp is "contained" in the main.layout tile. It does not inherently have any information about the tile it is contained in, so you have to pass any relevant attributes when you insert the page.

Greg


On Sep 30, 2005, at 4:59 AM, Java News wrote:

Hello,
I have problem with putting attributes in right context - my tiles
definitions look like:

<definition name=".add_product.form" path="/WEB-INF/pages/ add_product.jsp"
extends=".mainLayout">
<put name="title" value="Sample Page Title" />
</definition>

<definition name=".header" path="/WEB-INF/pages/tiles/header.jsp">
<put name="title" value="Sample Page Title" />
</definition>

What I would like to achieve is:
1) I would like that .header attribute "title" was passed from
.add_product.form, so i can have only one header definition and many
rendering pages like .add_product.form, .add_product.confirm,
.add_product.thank_you and also i dont want (or other words i can't) extend
header definition
2) I tried to put header in .add_product.form as:
<definition name=".add_product.form" path="/WEB-INF/pages/ add_product.jsp"
extends=".mainLayout">
<put name="title" value="Sample Page Title" />
<put name="header" value="/WEB-INF/pages/tiles/header.jsp">
</definition>

and use it in jsp page as:

<tiles:get name="header"/>

but when I used in header.jsp:

<h1><tiles:getAsString name="title"/></h1>

I got an error about lack of attr title in context:

11:38:22,134 ERROR [[action]] Servlet.service() for servlet action threw
exception
javax.servlet.jsp.JspException: ServletException in
'/WEB-INF/pages/tiles/header.jsp': Error - tag.getAsString : attribute
'title' not found in context. Check tag syntax
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(
InsertTag.java:921)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java: 460)
at
org.apache.jsp.WEB_002dINF.pages.add_005fproduct_jsp._jspx_meth_tiles_ get_0(
org.apache.jsp.WEB_002dINF.pages.add_005fproduct_jsp:136)
at org.apache.jsp.WEB_002dINF.pages.add_005fproduct_jsp._jspService(
org.apache.jsp.WEB_002dINF.pages.add_005fproduct_jsp:77)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(
JspServletWrapper.java:322)
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:810)

What should I do to put this attribute in right context - could you help me?

Best Regards,
Lee



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

Reply via email to