Uncaught ReferenceError: $ is not defined JSF Primefaces (h:head included)

Uncaught ReferenceError: $ is not defined JSF Primefaces (h:head included)

我有一个简单的 JSF 页面,显示来自 primefaces (Showcase) 的文本编辑器。
但是,没有显示文本编辑器。当我检查它时(chrome 中的 F12),我看到多个错误,第一个是:

core.js.xhtml:2 Uncaught ReferenceError: $ is not defined
at Object.resolveUserAgent (core.js.xhtml:2)
at Object.init (core.js.xhtml:2)
at core.js.xhtml:2

其他的是Uncaught TypeError: Cannot read 属性 'Tag from Primefaces' of undefined.



我读了那些问题:1 / 2,但是 我确实有 <h:head>
我错过了什么?

我的页面(index.xhtml):

<h:html xmlns="http://www.w3.org/1999/xhtml"
xmlns:b="http://bootsfaces.net/ui"
xmlns:p="http://primefaces.org/ui"  
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <h:outputStylesheet library="css" name="style.css"  />
    <h:outputScript library="js" name="script.js" />
</h:head>
<h:body>
    <p:textEditor value="#{textEditorController.text}" height="300" style="margin-bottom:10px"/>
    <p:commandButton value="Submit" action="#{textEditorController.submit}"/>
</h:body>
</h:html>

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>MusiglabelWEB</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>facelets.SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
  </context-param>
</web-app>

如果重要的话,我会使用多个项目(WEB、JPA、EJB、EAR)。

WEB项目中包含的库:

  • Primefaces 6.1(已下载 here
  • Bootsfaces 1.1.1(已下载 here

  • 这是 PrimeFaces 中的一个错误,我注册了它 here。当 p:textEditor 是最终视图中的第一个 PrimeFaces 组件时,它就会出现。

    要解决此错误,只需在它之前添加一些其他组件,您可以使其不呈现,否则它不会影响您的页面:

    <p:inputText rendered="false" />
    <p:textEditor />
    

    我遇到了同样的问题。 通过导入 jquery 和 jquery ui 解决,如下所示

    ...
        <h:head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
    </h:head>
    ...