我有一个简单的 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
其他的是未捕获的类型错误:无法读取未定义的属性“来自 Primefaces 的标签”。
我读了这些问题: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中的一个错误,我注册了它here 。当 p:textEditor 是最终 View 中的第一个 PrimeFaces 组件时,它就会显现出来。
要解决该错误,只需在其之前添加一些其他组件,您可以使其不呈现,这样就不会影响您的页面:
<p:inputText rendered="false" />
<p:textEditor />
关于jsf - Uncaught ReferenceError : $ is not defined JSF Primefaces (h:head included),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43832278/