2013-05-27 63 views
0

我一直在將應用程序從EJB遷移到JSF + Spring,並且這樣做,我將RichFaces從3.3.1更新到4.1.0。 現在我有以下問題所困擾,在鍍鉻控制檯顯示在RichFaces腳本中未定義jQuery

Uncaught ReferenceError: jQuery is not defined 
像RichFaces的-event.js,popupPanel.js RichFaces的腳本


我知道,在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> 

這裏的問題是不是收藏,但RichFaces.The 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> 

不過是我將應用程序遷移,代碼是相同的,控制檯不顯示任何錯誤

+0

你可以顯示你的文件的其餘部分?你直接導入jQuery嗎?你使用''嗎?你從'/ lib'文件夾中刪除了以前的庫嗎? – skuntsel

+0

已添加代碼。 如您所見,我使用了''標籤,但它仍然不起作用。 清除了'/ lib'文件夾,並且沒有以前的庫出現在那裏。 – Nav

回答

1

您應該按照正確的順序加載JavaScript庫。如果您看到渲染頁面的源代碼,您將看到jQuery被加載,或者根本沒有,因爲library="js"

修改列入這樣的:

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

注:

用於將來自RichFaces的該jQuery,您將無法使用$描述。您需要改用jQuery("your-selector")...。您還需要將LightBox庫放入<web-root>/resources/js/jquery.lightbox-0.5.js,以便找到它。

+0

但是在生成的html代碼中,RichFaces腳本在jQuery和LightBox之前,並且控制檯顯示它們是問題,而不是LightBox – Nav

+0

@Nav生成的代碼來自您的遷移版本或舊版本?即:RichFaces 3.3或RichFaces 4.1 –

+0

生成的htmls(前者和新的)都具有相同的腳本序列。首先出現RichFaces腳本,確切地說:'richfaces-event.js,popupPanel.js,popupPanelBorders.js,popupPanelSizer.js'。舊的是3.3.1,新的是4.1.01 – Nav