Richfaces捆绑的jQuery包含在webapp捆绑的JavaScript文件之后

时间:2012-08-17 19:14:19

标签: javascript jsf richfaces facelets

我最近将Richfaces库升级为 4.2.2.Final ,我注意到与Richfaces捆绑在一起的jquery库现在位于我的自定义脚本下方,使其无法使用

以下是生成的html:

<head><title lang="fr">Massaï, bronze, 2008 / Jean-Baptiste Martin Sculptures</title>
                <meta name="description" content="Sculpture en bronze d'une femme massai. 2008." lang="fr" />
        <meta name="keywords" content="Jean-Baptiste Martin, sculpture, sculpteur, oeuvre, bronze, portrait, statue, tête, visage, plâtre, moule, moulage, fonte, modèle, modelage, nu" lang="fr" />
        <link rel="icon" type="image/png" href="/images/favicon-32x32.png" />
        <link rel="stylesheet" href="/css/screen.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="/css/layout.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="/css/carousel.css" type="text/css" media="screen" />
                <script language="javascript" type="text/javascript" src="/js/jquery.mousewheel.js"></script>
                <script language="javascript" type="text/javascript" src="/js/jcarousellite_1.0.1.js"></script>
                <script language="javascript" type="text/javascript" src="/js/init-sculpture.js"></script>
                <script language="javascript" type="text/javascript" src="/js/jquery.formulaire-inscription.js"></script><script type="text/javascript" src="/javax.faces.resource/jsf.js.jsf?ln=javax.faces"></script><script type="text/javascript" src="/javax.faces.resource/jquery.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/richfaces.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/richfaces-queue.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/richfaces-base-component.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/richfaces-event.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/component-control.js.jsf?ln=org.richfaces"></script><script type="text/javascript" src="/javax.faces.resource/popupPanel.js.jsf?ln=org.richfaces"></script><script type="text/javascript" src="/javax.faces.resource/popupPanelBorders.js.jsf?ln=org.richfaces"></script><script type="text/javascript" src="/javax.faces.resource/popupPanelSizer.js.jsf?ln=org.richfaces"></script><link type="text/css" rel="stylesheet" href="/rfRes/popupPanel.ecss.jsf?db=eAG7mShzEgAFjAIg&amp;ln=org.richfaces" /><script type="text/javascript" src="/javax.faces.resource/status.js.jsf?ln=org.richfaces"></script>
</head>

以下是相应的facelets:

 <h:head>
        <ui:insert name="title-bar-title" />
        <ui:insert name="meta-description"/>
        <meta name="keywords" content="#{msg['meta.mots.clefs']}" lang="#{view.locale.language}"/>
        <link rel="icon" type="image/png" href="#{facesContext.externalContext.requestContextPath}/images/favicon-32x32.png" />
        <link rel="stylesheet" href="#{facesContext.externalContext.requestContextPath}/css/screen.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="#{facesContext.externalContext.requestContextPath}/css/layout.css" type="text/css" media="screen" />
        <link rel="stylesheet" href="#{facesContext.externalContext.requestContextPath}/css/carousel.css" type="text/css" media="screen" />
        <ui:insert name="javascript"/>
    </h:head>

有人可以帮我解决这个问题吗?

编辑:这是相应的js:

    <ui:define name="javascript">
        <script language="javascript" type="text/javascript" src="#{facesContext.externalContext.requestContextPath}/js/jquery.mousewheel.js"/>
        <script language="javascript" type="text/javascript"  src="#{facesContext.externalContext.requestContextPath}/js/jcarousellite_1.0.1.js"/>
        <script language="javascript" type="text/javascript"  src="#{facesContext.externalContext.requestContextPath}/js/init-sculpture.js"/>
        <script language="javascript" type="text/javascript"  src="#{facesContext.externalContext.requestContextPath}/js/jquery.formulaire-inscription.js"/>
    </ui:define>

编辑:按照建议修改后:

<link rel="icon" type="image/png" href="/images/favicon-32x32.png" /><link type="text/css" rel="stylesheet" href="/javax.faces.resource/css/screen.css.jsf" /><link type="text/css" rel="stylesheet" href="/javax.faces.resource/css/layout.css.jsf" /><link type="text/css" rel="stylesheet" href="/javax.faces.resource/css/carousel.css.jsf" /><script type="text/javascript" src="/javax.faces.resource/js/jquery.mousewheel.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/js/jcarousellite_1.0.1.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/js/init-sculpture.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/js/jquery.formulaire-inscription.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/jsf.js.jsf?ln=javax.faces"></script><script type="text/javascript" src="/javax.faces.resource/jquery.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/richfaces.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/richfaces-queue.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/richfaces-base-component.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/richfaces-event.js.jsf"></script><script type="text/javascript" src="/javax.faces.resource/component-control.js.jsf?ln=org.richfaces"></script><script type="text/javascript" src="/javax.faces.resource/popupPanel.js.jsf?ln=org.richfaces"></script><script type="text/javascript" src="/javax.faces.resource/popupPanelBorders.js.jsf?ln=org.richfaces"></script><script type="text/javascript" src="/javax.faces.resource/popupPanelSizer.js.jsf?ln=org.richfaces"></script><link type="text/css" rel="stylesheet" href="/rfRes/popupPanel.ecss.jsf?db=eAG7mShzEgAFjAIg&amp;ln=org.richfaces" /><script type="text/javascript" src="/javax.faces.resource/status.js.jsf?ln=org.richfaces"></script>

编辑:修改过的facelet:

<h:head>
    <ui:insert name="title-bar-title" />
    <ui:insert name="meta-description" />
    <meta name="keywords" content="#{msg['meta.mots.clefs']}" lang="#{view.locale.language}" />
    <link rel="icon" type="image/png" href="#{facesContext.externalContext.requestContextPath}/images/favicon-32x32.png" />
    <h:outputStylesheet name="css/screen.css"/>
    <h:outputStylesheet name="css/layout.css"/>
    <h:outputStylesheet name="css/carousel.css"/>
    <h:outputScript name="js/jquery.mousewheel.js" target="head"/>
    <h:outputScript name="js/jcarousellite_1.0.1.js" target="head"/>
    <h:outputScript name="js/init-sculpture.js" target="head"/>
    <h:outputScript name="js/jquery.formulaire-inscription.js" target="head"/>
</h:head>

1 个答案:

答案 0 :(得分:1)

您没有以正确的方式使用JSF资源管理。

删除

<ui:insert name="javascript"/>

替换笨拙的

<ui:define name="javascript">
    <script language="javascript" type="text/javascript" src="#{facesContext.externalContext.requestContextPath}/js/jquery.mousewheel.js"/>
    <script language="javascript" type="text/javascript"  src="#{facesContext.externalContext.requestContextPath}/js/jcarousellite_1.0.1.js"/>
    <script language="javascript" type="text/javascript"  src="#{facesContext.externalContext.requestContextPath}/js/init-sculpture.js"/>
    <script language="javascript" type="text/javascript"  src="#{facesContext.externalContext.requestContextPath}/js/jquery.formulaire-inscription.js"/>
</ui:define>

更简单(只需将模板放入模板以便最终放入<h:body>

<h:outputScript name="js/jquery.mousewheel.js" target="head" />
<h:outputScript name="js/jcarousellite_1.0.1.js" target="head" />
<h:outputScript name="js/init-sculpture.js" target="head" />
<h:outputScript name="js/jquery.formulaire-inscription.js" target="head" />
之后

您已将/js文件夹移动到公共网页内容的/resources文件夹中。

WebContent
 |-- resources
 |    `-- js
 |         |-- jquery.mousewheel.js
 |         |-- jcarousellite_1.0.1.js
 |         |-- init-sculpture.js
 |         `-- jquery.formulaire-inscription.js
 :