How to enforce loading of jQuery in RichFaces?

穿精又带淫゛_ 提交于 2019-12-22 08:45:00

问题


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>

回答1:


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.




回答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>




回答3:


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"/>


来源:https://stackoverflow.com/questions/18587769/how-to-enforce-loading-of-jquery-in-richfaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!