You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Raible, Matt" <Ma...@cable.comcast.com> on 2003/04/24 00:41:27 UTC

RE: Putting Javascript include files in in a Tiles environ ment ?

Here's what I do:

1.  In my tiles-config.xml file, I have a default set of javascript files
for the base definition:

    <!-- Base layout definition -->
	<definition name="baseLayout" path="/layouts/baseLayout.jsp">
		<put name="title.key"/>
		<put name="heading.key"/>
		<put name="header" value="/common/header.jsp"/>
		<put name="footer" value="/common/footer.jsp"/>
        <!-- Default Javascript File -->
        <putList name="scripts">
            <add value="/scripts/global.js"/>
            <add value="/scripts/helptip.js"/>
            <add value="/scripts/coolmenu4.js"/>
            <add value="/scripts/cm_addins.js"/>
		</putList>
        <!-- Default Stylesheet File -->
        <putList name="styles">
            <add value="/styles/default.css"/>
            <add value="/styles/coolmenu.css"/>
            <add value="/styles/helptip.css"/>
		</putList>
	</definition>

2.  Then in baseLayout.jsp, I list the javascript files out:

    <%-- Get Javascript List --%>
    <tiles:useAttribute id="scriptList" name="scripts" 
        classname="java.util.List" ignore="true"/>
    
    <c:forEach var="js" items="${scriptList}">
        <script type="text/javascript"
            src="<%=request.getContextPath()%><c:out
value="${js}"/>"></script>
    </c:forEach>

3.  If I want to override the default settings for a page, I just create a
new list:

    <!-- User Edit definition -->
    <definition name=".userDetail" extends=".mainMenu">
        <put name="title.key"  value="userDetail.title" />
        <put name="heading.key" value="userDetail.heading" />
        <put name="content" value="/WEB-INF/pages/userForm.jsp"/>
        <putList name="scripts">
            <add value="/scripts/global.js"/>
            <add value="/scripts/coolmenu4.js"/>
            <add value="/scripts/cm_addins.js"/>
            <add value="/scripts/selectbox.js"/>
		</putList>
    </definition>

It'd be nice if I could just "add" a new file, rather than replacing the
entire list of JavaScript files, but Tiles does not support this at this
point.

HTH,

Raible

> -----Original Message-----
> From: Kruse, Matt [mailto:MKruse@aquent.com]
> Sent: Wednesday, April 23, 2003 4:19 PM
> To: Struts Users Mailing List (E-mail)
> Subject: Putting Javascript include files in <HEAD> in a Tiles
> environment ?
> 
> 
> If I am using a complex tile setup, what is the best way to get my
> required
> javascript include files in the <HEAD> of my document?
> 
> Right now I have a "javascript include" tile, and each of my 
> definitions
> uses 'put' to include the libraries it needs, and this gets 
> put into the
> <HEAD> of the document. I can't put them into the actual body jsp, or
> they
> will appear in the body of the page, obviously.
> 
> Is using a 'put' really the best way to do this, forcing all my
> javascript
> include files to be defined in my tiles-defs.xml file? That 
> seems weird
> to
> me.
> 
> Thanks!
> 
> Matt Kruse
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org