I download jQuery built into RichFaces with:
<a4j:loadScript src="resource://jquery.js"/>
Next, I download the fancyBox jQuery plugin with:
<script type="text/javascript" src="/App/fancybox/jquery.fancybox-1.3.4.pack.js"/>
The plugin works fine when the page first loads, however, after making an ajax call using
<a4j:jsFunction name="myMethod" data="#{myController.jsonDataToReturn}" action="#{myController.doSomething()}" oncomplete="populateData(data);"> <a4j:actionparam name="selectedTag" assignTo="#{myController.selectedTag}"/> </a4j:jsFunction>
the plugin stops working. Tests show that the a4j:loadScript reloaded with every ajax call, thereby reloading the jQuery variable, which loses the plugin connected.
The current workaround is to load jQuery by placing the <rich:jQuery query="fn" /> somewhere on the page. It does nothing except to force jQuery to load, but since it does not use a4j, jQuery does not restart when ajax calls.
However, is there a clean solution for this? I am using RichFaces 3.3.3, which includes jQuery 1.3.2.
Update
FancyBox is loading:
jQuery(document).ready( function(){ jQuery('.fancyboxLink').live('click',aclick); }); function aclick(){ jQuery.fancybox({ href: '#{facesContext.externalContext.requestContextPath}/webpage.xhtml', type:'iframe', width:710, height:510, padding:0, margin:0, hideOnOverlayClick:false, overlayColor:'#000' }); return false; }
After the first ajax call, jQuery no longer contains fancybox.