2015-11-27 12:45 GMT+01:00 Lukasz Lenart <lukaszlen...@apache.org>: > The problem is with AttributeContext and ArrayStack. When evaluating > ftl file I see three AttributeContexts - empty, > with-attributes-from-tiles.xml, empty - and the last empty is used to > evaluate the ftl :\ > > In BasicTilesContainer method render() looks like this > > protected void render(TilesRequestContext request, Definition definition) { > AttributeContext originalContext = getAttributeContext(request); > BasicAttributeContext subContext = new > BasicAttributeContext(originalContext); > subContext.inherit(definition); > > pushContext(subContext, request); > > try { > render(request, subContext); > } finally { > popContext(request); > } > } > > the first line will create an empty AttributeContext and will push to > the stack - why? Then the proper AttributeContext will be created and > pushed again (with values from tiles.xml). I cannot figure out where > the third ActionContext is created.
I think I understand - AttributeContext is created per a tile (ie. /tiles/layout.jsp, /tiles/menu.jsp, etc) and it isn't possible to use it outside of the tile - which looks like a bug to me :) I have a very simple tiles.xml: <tiles-definitions> <definition name="baseLayout" template="/tiles/layout.jsp"> <put-attribute name="title" value="Template"/> <put-attribute name="header" value="/tiles/header.jsp"/> <put-attribute name="menu" value="/tiles/menu.jsp"/> <put-attribute name="body" value="/tiles/body.jsp"/> <put-attribute name="footer" value="/tiles/footer.ftl"/> </definition> <definition name="hello" extends="baseLayout"> <put-attribute name="title" value="Hello"/> <put-attribute name="body" value="/example/HelloWorld.jsp"/> </definition> </tiles-definitions> and now an attribute "title" is only accessible inside "layout.jsp", it won't be accessible in header.jsp, menu.jsp and so on as for each of this tile a new empty AttributeContext is created. I would assume that the attributes will be inherited in that case, but they aren't. I have tested this by simply adding <tiles:insertAttribute name="title"/> tag to menu.jsp and got exception: org.apache.tiles.template.NoSuchAttributeException: Attribute 'title' not found How can I tell Tiles to inherit attributes? Regards -- Ćukasz + 48 606 323 122 http://www.lenart.org.pl/