Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes Simple Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Simple Question" Watch "Simple Question" New topic
Author

Simple Question

Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
We are using Tiles in out application. We have a defintion of headerBodyFooter and then extensions of that defintion for particular body JSPs.

I need to include a reference to Java Script file or maintain JavaScript in the "body" jsp. The body JSP does not include the <head></head> tag as that is located in the layout. Including the script rerefence in the body without it being in <head> does not conform to HTML standards I beleive.

Any recommendations of how you have acheived this?

Thanks in advance.


Never be satisfied with anything less than the best and you will surely pass the test...
Durgaprasad Guduguntla
Ranch Hand

Joined: Oct 20, 2003
Posts: 99
You can achieve this by configuring the path of javascript file in the tiles definition and expose that
name in the master layout. The child definitions can override the javscript file value
and thus can render different javascript files within the <head> element itself.
Please take a look at the following code snippets:
tiles-defs.xml


masterlayout.jsp:



Hope this helps.


Thanks,<br />Durgaprasad<br />SCJP1.4, SCWCD1.4, SCBCD1.3,<br />SCEA
Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
Thanks much for the tip. This would work great except we have a case where we include multiple JS files. Any ideas on the same?
Durgaprasad Guduguntla
Ranch Hand

Joined: Oct 20, 2003
Posts: 99
If that is the case, you can still have them using tiles. Move the script elements generation into a separate tile with a JSP. You can configure multiple JS files in tiles-defs.xml. The following code snippets would help you:
tiles-defs.xml:



jslayout.jsp:



Hope this resolves your requirement.
Kalichar Rangantittu
Ranch Hand

Joined: Jan 15, 2002
Posts: 240
It does.Thanks much :-)
Vidhir Kaup
Greenhorn

Joined: Nov 04, 2005
Posts: 1
I was stuck with the same problem. Your response helped me solve it. Thanks a lot.

Originally posted by Kalichar Rangantittu:
Thanks much for the tip. This would work great except we have a case where we include multiple JS files. Any ideas on the same?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Great solution, Durgaprasad!

I've included it in the Struts FAQ. I hope you don't mind. If you do, just let me know, and I'll take it out.

Cheers,

Merrill


Merrill
Consultant, Sima Solutions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Simple Question