4

I'm using jQuery on my page. However, I do NOT use RichFaces tags on every page. Subsequently, jQuery is NOT injected by RF in every page. In order to avoid loading an additional jQuery library, how do I properly instruct RichFaces to load its jQuery own library?

This is an issue, because the RF-jQuery library overwrites my custom jQuery that I load. Also, the RF-jQuery libraries are always the last libraries to load, which is not good neither, because I need jquery-ui.js and jquery-migrate-1.2.1.min.js to load AFTER a jQuery library has been loaded.

<head>
    <!-- JS -->
    <span id="out">
        Richfaces-jQuery enforce with a4j:outputPanel
    </span>

    <script src="/ccms/resources/js/jquery-ui.js"></script>
    <script src="/ccms/resources/js/jquery-migrate-1.2.1.min.js"></script>

    <!-- The CK editor -->
    <script src="/ccms/resources/ckeditor_4_2_custom/ckeditor.js"></script>
    <script src="/ccms/resources/js/jquery.capty.min.js"></script>

    <!-- &lt;ui:debug hotkey=&quot;x&quot; /&gt; -->
    <script type="text/javascript" src="/ccms/javax.faces.resource/jsf.js.jsf?ln=javax.faces&amp;stage=Development"></script>
    <script type="text/javascript" src="/ccms/org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.3.3.Final/Packed/jquery.js"></script>
    <script type="text/javascript" src="/ccms/org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.3.3.Final/Packed/packed/packed.js"></script>
    <link type="text/css" rel="stylesheet" href="/ccms/org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.3.3.Final/Packed/DEFAULT/packed/packed.css" />
</head>
honk
  • 9,137
  • 11
  • 75
  • 83
feder
  • 1,775
  • 5
  • 25
  • 36

4 Answers4

6

RichFaces 4.x-bundled jQuery is available as follows:

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

Yes, astonishingly without any library!

You only need to make sure that you use <h:head> instead of <head>. I also strongly recommend to load your own JS resources by <h:outputScript> as well.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
2

You can force the load of JQuery by adding this (works with RichFaces 3.x):

<a4j:loadScript src="resource://jquery.js" />

For RichFaces 4.x, see this thread: RichFaces 4 replacement for <a4j:loadScript>

Community
  • 1
  • 1
LaurentG
  • 11,128
  • 9
  • 51
  • 66
  • Thanks @LaurentG. But that tag is neither in my tag completion nor it is described in the documentation: docs.jboss.org/richfaces/latest_4_3_X/Component_Reference/en-US/… I wish it was. – feder Sep 03 '13 at 09:03
  • Sorry, my solution works for Richfaces 3.x. I updated the answer. – LaurentG Sep 03 '13 at 09:40
  • 1
    Now it's loaded twice. Once by my instruction and once by richfaces. I left this path. I'm operating now with two jQuery instances. Using the `var jq10 = jQuery.noConflict(true);` which put the primary loaded jquery library to the assigned var (jq10 in my case). It still is suboptimal loading two libraries, if you only need one. However, cannot waste hours here. – feder Sep 03 '13 at 13:38
0

If your h:outputScript instruction is not inside of h:head, add target="head" parameter to make sure the library is included only once:

<h:outputScript name="jquery.js" target="head"/>
Andrey
  • 6,526
  • 3
  • 39
  • 58
  • Hi Andrey, It's available. The priority loading of RF is the issue to overcome. But nevermind, I went on. – feder Sep 05 '13 at 12:33
0

RichFaces 4.5 finally put their JavaScript code in a library, so to include their copy of jQuery you need to use

<h:outputScript name="jquery.js" library="org.richfaces" />
Yay295
  • 1,628
  • 3
  • 17
  • 29