On May 8, 2006, at 7:49 AM, Troy Bull wrote:

I have read through the documentation and haven't seen this example (I may be blind). The error I get is : [ServletException in:/header.jsp] Error - tag.getAsString : attribute 'title' not found in context. Check tag syntax'

Ah, I'm sorry. I missed that you were trying to use the title attribute in the included header page. It looks like you're basically using the example from the doc, but trying to add the getAsString to the header.jsp page. I've needed the same functionality on several occasions. Here's what's happening:

Tiles creates a ComponentContext with 2 attributes title and header. When it sees <tiles:insert attribute="header"/> in layout.jsp it invokes the InsertTag. InsertTag creates a sub-ComponentContext that it puts in request scope. If InsertTag is invoked with no attributes that sub-context is empty. That's why your "title" attribute is not being passed along.

There are a couple of ways to hack this:

1) In layout.jsp use the importAttribute tag to put the "title" attribute in request scope. 2) In layout.jsp use the importAttribute tag to put "title" in page scope. If you can use EL you can then do the following:

<tiles:insert name="header">
        <tiles:put name="title" value="${pageScope.title}"/>
</tiles:insert>

If you're not using EL, you can do the same with scriptlet (I think the following is legal):

<tiles:insert name="header">
<tiles:put name="title" value="<%= pageContext.findAttribute ("title"); %>"/>
</tiles:insert>

But, I think those are hacks. It would be nice if Tiles automatically propagated its context down the "component tree". Does anyone know why it doesn't do that or if there are good motivations to not do that? There may be history behind this issue that I missed. Perhaps we could add an attribute to the insert tag that would do this.

Greg


troy


Greg Reddin said the following on 5/5/2006 3:01 PM:
Have you tried the instructions in the tiles documentation?

    http://struts.apache.org/struts-action/struts-tiles/

I think it describes your use case. Are you trying this and getting some kind of error you can send us?

Thanks,
Greg

On May 5, 2006, at 1:33 PM, Troy Bull wrote:

Greetings

I am new to tiles and so far I like it. I have a question though. Seems like it should be easy to do but I haven't seen how yet. I will try to describe the situation as concisely as I can. This can be reproduced with just 2 jsp files.

layout.jsp (interesting lines only)

<title>
     <tiles:getAsString name="title"/>
</title>
</head>
<HR>
<tiles:insert attribute="header"/>

header.jsp

<hr><tiles:getAsString name="title"/></h2>
<hr>



int my tiles-defs.xml I have

 <definition name="main.layout" path="/layout.jsp">
    <put name="title"  value="This is the title"/>
    <put name="header" value="/header.jsp"/>
</definition>


And finally, what I want is to display in the browser "This is the title" inside an H2 tag so that on each screen of my app the user gets visual feed back for what page they are on.

This seems to me like something I should be able to do but I dont know how, anyone with any tips I am greatfull.

thanks
troy

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




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


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




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

Reply via email to