How to use jQuery and jQuery plugins with PrimeFaces

PrimeFaces already ships with jQuery bundled, yet you’ve downloaded and installed another one which would only conflict with PrimeFaces bundled jQuery. I’m sure that if you have paid a bit more attention and love to the webbrowser’s builtin JavaScript console, you would have seen JS errors. And, if you checked the JSF-generated HTML output via rightclick, View Source in webbrowser, you would have seen another jquery.js file being included in HTML <head>.

You need to remove the following line:

<script type="text/javascript" src="https://stackoverflow.com/questions/11112058/js/jquery-1.7.1.min.js"></script>

In case you have pages which do not necessarily use PrimeFaces components, and thus its jQuery wouldn’t automatically be included, then you’d need to explicitly load its bundled jQuery by a proper <h:outputScript>.

<h:outputScript library="primefaces" name="jquery/jquery.js" />

Note that using <h:outputScript> does not end up in a duplicate script include on pages which actually use PrimeFaces components.

See also:

Leave a Comment