What I do is in my layout I use code like:
<tiles:importAttribute scope="request"/>
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/default.css"
title="default" />
<c:forEach items="${styles}" var="s">
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/${s}" />
</c:forEach>
<script language="JavaScript" type="text/javascript"
src="${pageContext.request.contextPath}/script/util.js"></script>
<c:forEach items="${scripts}" var="s">
<script language="JavaScript" type="text/javascript"
src="${pageContext.request.contextPath}/${s}"></script>
</c:forEach>
Then in my tiles.xml I have a template definition at the top like:
<definition name="default-layout" template="/layout/default-layout.jsp">
<put-attribute name="menu-bar" value="/tiles/menu-bar.jsp" type="template"/>
<put-attribute name="left-nav" value="/tiles/left-nav.jsp" type="template"/>
</definition>
Then I extend this and override the pieces that need to change for that page:
<definition name="site-manager" extends="default-layout">
<put-attribute name="title" value="Site Manager" type="string"/>
<put-attribute name="body" value="/body/site-manager.jsp" type="template"/>
<put-list-attribute name="styles">
<add-attribute value="/css/tab.css" type="string"/>
</put-list-attribute>
<put-list-attribute name="scripts">
<add-attribute value="script/cookies.js" type="string"/>
<add-attribute value="script/tab.js" type="string"/>
</put-list-attribute>
</definition>
This seems to work well, is very flexible and keeps things that belong
in the header where they belong.
(*Chris*)
On Tue, May 6, 2008 at 2:42 PM, Adam Hardy
<[EMAIL PROTECTED]> wrote:
>
> Antonio Petrelli on 06/05/08 18:02, wrote:
>
> > 2008/5/6 Adam Hardy <[EMAIL PROTECTED]>:
> >
> > > So if I made a taglib that stored the CSS in its body into the request
> > > attribute, e.g. requestScope.specialCss, a bit like this:
> > >
> > > <adam:style var="specialCss">
> > > #ContextBody div.repo span { width: 25px; }
> > > </adam:style>
> > >
> > > then I could achieve this? Or do you mean that it's not possible?
> > >
> >
> > It's not possible to put it in the body and hope that it will be
> > processed in the header, simply because the header gets renderer
> > before the body, and when you render the body it's too late to process
> > the header.
> > I think that your option is to do some pre-rendering processing, for
> > example using a ViewPreparer, to store the extra CSS items, and then
> > use them when rendering the <head>.
> >
>
> OK. Perhaps I could write a ViewPreparer that greps the JSP and extracts
> the CSS declared there.
>
> I could write a simple taglib for the JSP to surround the CSS which would
> identify the portion to extract and also prevent it displaying when the JSP
> loads.
>
> This depends on the ViewPreparer getting the name of the JSP file.
> Presumably that's in the AttributeContext.
>
>
> Regards
> Adam
>