在RichFaces脚本中没有定义jQuery

时间:2013-05-27 14:11:24

标签: jsf-2 richfaces

我一直在将aplication从EJB迁移到JSF + Spring并且这样做,我将RichFaces从3.3.1更新到4.1.0。 现在我正在努力解决以下问题,即chrome中的控制台显示

Uncaught ReferenceError: jQuery is not defined
在RichFaces脚本中的

,如richfaces-event.js,popupPanel.js 我知道在html文件的标题中,包括jQuery文件应该是第一个,但是我已经查看了前一个应用程序,这个脚本也包含在jQuery之前,没有出现错误。更重要的是,我现在不知道如何改变这一点,因为这些脚本是通过以下方式隐式添加的:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich">

如何解决此问题?

<f:view contentType="text/html" locale="#{localeSelector.language}">
<h:head>
    <title>#{messages['news.title']}</title>
    <link rel="stylesheet" type="text/css" href="css/styles.css" />
    <link rel="stylesheet" type="text/css"
        href="css/jquery.lightbox-0.5.css" media="screen" />
    <script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>

</h:head>


<h:body>
    <h:outputScript name="jquery.js" library="js" target="head" />
    <div id="container">
            </div>
    </h:body>
</f:view>
</html>

这里的问题不是lightbox而是RichFaces.生成的html代码是:

<script type="text/javascript" src="/ESA/javax.faces.resource/richfaces-event.js.xhtml">        </script>
<script type="text/javascript" src="/ESA/javax.faces.resource/popupPanel.js.xhtmlln=org.richfaces"></script>
<script type="text/javascript" src="/ESA/javax.faces.resource/popupPanelBorders.js.xhtml?ln=org.richfaces"></script>
<script type="text/javascript" src="/ESA/javax.faces.resource/popupPanelSizer.js.xhtml?ln=org.richfaces"></script>
<script type="text/javascript" src="/ESA/javax.faces.resource/jquery.js.xhtml?ln=js">   </script>
<script type="text/javascript" src="/ESA/javax.faces.resource/jquery.lightbox-0.5.js.xhtml?ln=js"></script>

但是我正在迁移的应用程序,代码是相同的,控制台没有显示任何错误

1 个答案:

答案 0 :(得分:1)

您应该按正确的顺序加载JavaScript库。如果您看到呈现页面的来源,您会看到jQuery被加载到第二个或根本不加载,因为library="js"

像这样修改包含:

<h:head>
    <h:outputScript name="jquery.js" />
    <h:outputScript name="js/jquery.lightbox-0.5.js" />
</h:head>

注意:

使用的jQuery将来自RichFaces,您将无法使用$描述符。您需要使用jQuery("your-selector")...代替。您还需要将LightBox库放在<web-root>/resources/js/jquery.lightbox-0.5.js中,以便找到它。