Sorry for the length of the post, but here's what I use to solve the problem
you mentioned. My defaultLayout.jsp has this header:
<head>
<c:forEach items="${metatags}" var="meta">
<meta http-equiv="${fn:substringBefore(meta,':')}"
content="${fn:trim(fn:substringAfter(meta,':'))}" />
</c:forEach>
<c:forEach items="${metadata}" var="meta">
<meta name="${fn:substringBefore(meta,':')}"
content="${fn:trim(fn:substringAfter(meta,':'))}" />
</c:forEach>
<title>${title}</title>
<link rel="stylesheet"
href="${pageContext.request.contextPath}/style/default.css" title="default"
/>
<link rel="stylesheet"
href="${pageContext.request.contextPath}/style/jquery-ui/ui-lightness/jquery-ui.css"
/>
<link rel="stylesheet"
href="${pageContext.request.contextPath}/style/jquery.alertbox.css" />
<c:forEach items="${styles}" var="s">
<link rel="stylesheet"
href="${pageContext.request.contextPath}/style/${s}" />
</c:forEach>
<tiles:insertAttribute name="style" ignore="true"/>
<script
src="${pageContext.request.contextPath}/script/jquery.js"></script>
<script
src="${pageContext.request.contextPath}/script/jquery-ui/jquery-ui.min.js"></script>
<c:forEach items="${scripts}" var="s">
<script src="${pageContext.request.contextPath}/script/${s}"></script>
</c:forEach>
<script>
<tiles:insertAttribute name="script" ignore="true"/>
</script>
</head>
This gives me lots of control over what gets included in each page. Here's
a snippet from the tiles.xml:
<definition name="default-layout" template="/layout/default-layout.jsp">
<!-- title, style, styles*, script, scripts*, body -->
<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>
<definition name="meal-log" extends="default-layout">
<put-attribute name="title" value="Anodyzed Exerceo - Meal Log"
type="string"/>
<put-attribute name="body" value="/body/meal-log.jsp" type="template"/>
<put-list-attribute name="styles">
<add-attribute value="nutrition-facts.css" type="template"/>
</put-list-attribute>
<put-list-attribute name="scripts">
<add-attribute value="jquery.htmlutils.js"/>
<add-attribute value="jquery.print.js"/>
<add-attribute value="jquery.validate.js"/>
</put-list-attribute>
</definition>
Hope that gives you some ideas.
(*Chris*)
On Wed, Dec 8, 2010 at 1:56 PM, acec acec <[email protected]> wrote:
> Hi,
> I am a new user of tiles.
>
> It seems tiles can put jsp together easily. Do we have any best practice
> example to handle css files and javascript files?
>
> For example, I can create a "defaultLayout", which includes a heard and
> foot.
>
> <definition name="defaultLayout"
> template="/WEB-INF/jsp/template/layout/default.jsp">
> <put-attribute name="header"
> value="/WEB-INF/jsp/template/component/header.jsp" />
> <put-attribute name="footer"
> value="/WEB-INF/jsp/template/component/footer.jsp" />
> </definition>
>
> <definition name="homeLayout" extends="defaultLayout">
> <put-attribute name="body" value="/WEB-INF/jsp/template/body/home.jsp"/>
> </definition>
>
> <definition name="aboutLayout" extends="defaultLayout">
> <put-attribute name="body" value="/WEB-INF/jsp/template/body/about.jsp"/>
> </definition>
>
> My homeLayout and aboutLayout will use different css files and javascript
> files, how can I put those files together?
>
> Thanks a lot.
>
>
>