Back Forum Reply New

Spring/Tiles template .. lt;headgt;lt;/headgt;

Hi,

I'm trying to make up some master templates using tiles, and I'm wondering if anyone can tell me if its possible to 'inject' strings from the page using the template.. er an example will probably explain it a bit better..

say I've a template like
template.jsp

Code:
lt;htmlgt;
lt;headgt;
lt;meta from-equiv=quot;Content-Typequot; content=quot;text/html; charset=utf-8quot; gt; lt;META from-EQUIV=quotragmaquot; CONTENT=quot;no-cachequot;gt; lt;META from-EQUIV=quot;Expiresquot; CONTENT=quot;-1quot;gt; lt;meta from-equiv=quot;Content-Languagequot; content=quot;plquot;gt; lt;meta from-equiv=quot;Cache-Controlquot; content=quot;no-store, no-cache, must-revalidate, Post-Check=0, Pre-Check=0quot;gt; lt;script type=quot;text/javascriptquot; src=quot;lt;c:ucl value=quot;/resources/dojo/dojo.jsquot; /gt;quot;gt; lt;/scriptgt; lt;script type=quot;text/javascriptquot; src=quot;lt;c:ucl value=quot;/resources/spring/Spring.jsquot; /gt;quot;gt; lt;/scriptgt; lt;script type=quot;text/javascriptquot; src=quot;lt;c:ucl value=quot;/resources/spring/Spring-Dojo.jsquot; /gt;quot;gt; lt;/scriptgt; lt;tiles:insertAttribute name=quot;headsquot;/gt;
lt;/headgt;

lt;body class=quot;tundraquot;gt;
lt;table cellpadding=quot;5quot; cellspacing=quot;5quot; border=quot;1quot; width=quot;100%quot;gt; lt;trgt;  lt;td colspan=quot;2quot; id=quot;topquot; width=quot;100%quot;gt;  lt;tiles:insertAttribute name=quot;bannerquot;/gt;  lt;/tdgt; lt;/trgt;     lt;trgt;         lt;td id=quot;leftquot; width=quot;150pxquot;gt;lt;tiles:insertAttribute name=quot;menuquot; /gt;lt;/tdgt;         lt;td id=quot;rightquot;gt;lt;tiles:insertAttribute name=quot;bodyquot; /gt;lt;/tdgt;     lt;/trgt;     lt;trgt;  lt;td colspan=quot;2quot; id=quot;bottomquot; width=quot;100%quot;gt;  lt;tiles:insertAttribute name=quot;footerquot;/gt;  lt;/tdgt; lt;/trgt; lt;/tablegt;
lt;/bodygt;
now I want to create a page, but I want to insert lt;scriptgt;s into the head, and these change per page..

Is it possible to modify the 'heads' tiles attribute from the page implementing the template?

I'm sure I could do something in the definitions file, but to be honest, I want to keep the script local to the page instead of spreading code all around the place.

Using tiles alone, is the only option to create 2 files? one to replace the body and one to replace the head attributes? ... so for a jsp like page1, my definition might look likeCode: lt;definition name=quot;t_welcome.htmquot; template=quot;/WEB-INF/jsp/t_template.jspquot;gt;     lt;put-attribute name=quot;bodyquot; value=quot;/WEB-INF/jsp/t_welcome.jspquot;/gt;     lt;put-attribute name=quot;headsquot; value=quot;/WEB-INF/jsp/t_welcome_header.jspquot;/gt;     lt;put-attribute name=quot;menuquot; value=quot;/WEB-INF/jsp/includes/menu.jspquot;/gt;     lt;put-attribute name=quot;bannerquot; value=quot;/WEB-INF/jsp/includes/banner.jspquot;/gt;     lt;put-attribute name=quot;footerquot; value=quot;/WEB-INF/jsp/includes/footer.jspquot;/gt; lt;/definitiongt;
Kindest regards,

Bal

doh .. I was using the wrong view class, using org..web.servlet.view.tiles2.TilesV  iew now so I can also use jstl.. as far as I know, I *think* I can do what I want using jstl as opposed to tiles.. just looking how to go about it now

I have a master template.jsp that I use for all my other pages and on some of the pages I need to include new lt;scriptgt; tags so this is what works for me.

tiles definitions:Code:
lt;definition name=quot;templatequot; template=quot;/WEB-INF/views/common/template.jspquot;gt;   lt;put-attribute name=quot;headerquot; value=quot;/WEB-INF/views/common/header.jspquot;/gt;   lt;put-attribute name=quot;footerquot; value=quot;/WEB-INF/views/common/footer.jspquot;/gt;   lt;put-attribute name=quot;customCssAndJsIncludequot; value=quot;quot;/gt;
lt;/definitiongt;lt;definition name=quot;somePagequot; extends=quot;templatequot;gt;   lt;put-attribute name=quot;titlequot; value=quot;Some Page Detailsquot;/gt;   lt;put-attribute name=quot;bodyquot; value=quot;/WEB-INF/views/somePage/viewDetails.jspquot;/gt;   lt;put-attribute name=quot;customCssAndJsIncludequot; value=quot;/WEB-INF/views/common/mapping_js_include.jspquot;/gt;
lt;/definitiongt;
include this into the head section of your template.jspCode:
lt;tiles:insertAttribute name=quot;customCssAndJsIncludequot; /gt;

The quot;mapping_js_include.jspquot; file just has lt;scriptgt; tags within it.  Using this method I can add a single new lt;scriptgt; tag to a given page or I could add 5 new lt;scriptgt; tags to a given page.  It works out well for me.

Hope this helps.
¥
Back Forum Reply New