wood burning stoves*
The moose likes Struts and the fly likes Tiles and image preloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Tiles and image preloading" Watch "Tiles and image preloading" New topic
Author

Tiles and image preloading

Eric Sexton
Ranch Hand

Joined: Sep 12, 2003
Posts: 133
I'm using tiles in an app and the <body> tag is in it's own jsp that includes the other tiles files to complete the layout. If I want to preload images for each jsp how can I accomplish this since the <body> tag is going to be used for every display?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

Not sure what you mean by "preload images for each jsp". The JSP doesn't load images, the client browser does. If you want to help the client browser load images faster, specify the width and height of images in your markup/tags.


Junilu - [How to Ask Questions] [How to Answer Questions]
Eric Sexton
Ranch Hand

Joined: Sep 12, 2003
Posts: 133
I should have explained it a bit better. This is a methodology that will make the 'mouse over' images for buttons loaded right away into the browser cache with JavaScript. I use the onLoad event of the body tag.
So without having a body tag for each individual jsp because of the use of tiles, I'm stuck.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

Originally posted by Eric Sexton:
I should have explained it a bit better. This is a methodology that will make the 'mouse over' images for buttons loaded right away into the browser cache with JavaScript. I use the onLoad event of the body tag.
So without having a body tag for each individual jsp because of the use of tiles, I'm stuck.

I still don't see how this would matter. JavaScript is processed by the client, not when the tiles are being put together so again, the JSP engine has nothing to do with loading your images.
Each JSP does not have to have its own body tag. You can have the body tag and the JavaScript that preloads the images in the layout and all the content in your tiles. The only thing you can't do is to have the opening and closing tags of custom JSP tags on separate pages. Other than that you shouldn't have any problem splitting the content into separate JSPs. When the tiles are all put together they go back to the client as a single HTML page.
Example:
// layout.jsp
<html:html>
<script type="text/javascript" language="JavaScript"
src="<tiles:getAsString name="imageLoadScript" />" />
<body on load="<tiles:getAsString name="imageLoadScriptProcName">" >
<tiles:insert attribute="header" />
<tiles:insert attribute="body" />
<tiles:insert attribute="footer" />
</body>
</html:html>

then in your tiles-def, you can just define puts:
<put name="imageLoadScript" value="myMenuImages.js" />
<put name="imageLoadScriptProcName" value="preLoadMenuImages()" />
You don't even have to make it that complicated if you have only one script to preload your images -- just plug the names in directly into the layout.
[ October 24, 2003: Message edited by: Junilu Lacar ]
Eric Sexton
Ranch Hand

Joined: Sep 12, 2003
Posts: 133
I know this. I'm just saying that I am required to have all the images for each screen loaded into cache when the page is loaded. The JavaScript is really nothing to do with the question. I was simply not understanding how to make each of these pages load different images, since the <body> was in a different jsp. Your code helped. I'll use puts and that will solve my problem. I just wasn't seeing the solution and it's pretty simple. Thanks for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tiles and image preloading
 
Similar Threads
confusion on struts tile
Simple Question
Struts modules and html:form
Passing Tiles into an IFRAME.
HELP with tiles