Primefaces JS 在其他资源之前插入,导致错误

Primefaces JS Inserted before other resources causing error

本文关键字:插入 错误 JS 其他 资源 Primefaces      更新时间:2023-09-26

我使用的是JSF2.0和Eclipse Indigo,就在最近,我将PrimeFaces库添加到我的构建路径中。在此之前,我有一个"灯箱"通过使用jquery1.7.2 + colorbox工作。我有以下内容包括:

<h:outputStylesheet library="css" name="style.css" type="text/css"/>  
<h:outputStylesheet library="css" name="colorbox.css" type="text/css"/>        
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>  
<h:outputScript library="js" name="jquery.colorbox.js" target="head"/>

资源位于 WebContent/resources/js .

添加PrimeFaces后,我的"灯箱"不再工作,因为找不到colorbox功能。在查看了 JSF2 生成的源代码后,我注意到该库在我的jquery.colorbox.js上方插入了它自己的 jQuery 版本,因此 colorbox 库无法使用 jQuery 库。此外,缺少jquery.colorbox.js包含。

如何将 PrimeFaces JavaScript 库重新定位到页面上的其他位置?为什么我的jquery.colorbox.js没有像以前那样加载?

我的实际页面可能有用。它就在这里。

我仍然从Chrome中的JavaScript控制台收到相同的错误。当页面加载时,我得到这个:

Uncaught ReferenceError: jQuery is not defined

当我单击我的彩盒链接时,以下内容:

Uncaught TypeError: Object [object Object] has no method 'colorbox'
(anonymous function):8080/g5.ambience/:24
b.event.dispatchjquery.js.html:16
b.event.add.bD.handle.bB

即使有丹尼尔斯的建议,这里也是产生的来源:http://pastie.org/3851179

1(尝试使用Primefaces捆绑的jQuery(3.2版本使用1.7.1 jQuery(

替换

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>  

<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<h:outputScript target="head">
    $ = jQuery;
</h:outputScript>

编辑

2(另一种选择是在加载捆绑的primefaces之前加载你的jQuery和colorbox插件(没有测试,甚至不确定它会工作,所以不建议:)

(
<f:facet name="first">
    <h:outputScript library="primefaces" name="jquery/jquery.js"/>
    <h:outputScript target="head">
        $ = jQuery;
    </h:outputScript>
</f:facet>
<h:outputScript library="js" name="jquery.colorbox.js" target="head"/>