jQuery not loaded if no tapestry-jquery component included?

147 views
Skip to first unread message

Ronin

unread,
May 30, 2014, 2:58:20 PM5/30/14
to tapestry...@googlegroups.com
Hello,

I've been stuck for quite some time on jquery not working in my tapestry project, despite using tapestry-jquery. This is a new project so I want to go jquery only (no prototype preferably). Just a quick how-to-reproduce to eliminate a lot of questions:

1) use maven to generate a new, clean tapestry project (5.3.7)
2) add tapestry5-jquery to pom
4) open index.tml and add a simple piece of jquery code like http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide_p (I'm copy-pasting only the script tags that contain document.ready function and the p tags and button. I'm NOT copying the first script tag that imports jquery)
5) run project, the script works fine. no console errors. so tapestry-jquery is working fine and has automatically included and imported jquery in the HTML source. (doubly verified by checking the statements in HTML source file)
4) remove the sample application's jquery-using components:
- in index.tml, remove the zone tags and actionlink that refers to the zone
- in index.java, remove the zone injectcomponent and onincrementFromAjax
- in layout.tml, remove <t:alerts>
- just for clarity, we KEEP the little jquery script that we added earlier.
5) run project. script does NOT work. Console shows "$ is not defined". No more jquery includes in HTML source.

A simple example, but the same is true for any external jquery libraries (prettyPhoto, etc) that I import and which don't work if I don't include at least one of tapestry-jquery's components. 

I'm not entirely sure, but I take it that tapestry-jquery detects that none of its jquery components are being used and therefore doesn't bother including jquery as a whole? 
In and of itself this is a fine optimization, but is there no way to switch it off so even if I don't use any of tapestry-jquery's components, it still includes jquery? I'd prefer not to  include jquery manually because then later if I happen to use a zone after all tapestry-jquery will kick in and include jquery a second time (and probably a different version too). 

Is there a clean solution to this?

Thanks guys!

Emmanuel DEMEY

unread,
May 31, 2014, 2:42:35 PM5/31/14
to tapestry...@googlegroups.com
Hi, 

I think this problem is totally normal. 

If I remember well, Tapestry Javascript stack is loaded only when it is needed. 

you can maybe import the Tapestry Javascript stack in your layout class with the @Import Annotation. The key of the stackk is : InternalConstants.CORE_STACK_NAME

Manu
Reply all
Reply to author
Forward
0 new messages