jsf - PrimeFaces CSS 外观缺失和 JS "Uncaught Reference Error: PrimeFaces is not defined"

标签 jsf primefaces

我正在尝试使用 Primefaces 中的选择列表。当页面呈现时,Chrome 中的 javascript 引擎找不到 Primefaces 对象。我收到以下错误“Uncaught ReferenceError: PrimeFaces is not defined”。我是否缺少在我的 .xhtml 文件中包含任何资源 (js)?请指教。谢谢。

Xhtml

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<link rel="stylesheet" type="text/css"
    href="../jquery-ui-1.8.23.custom/css/ui-lightness/jquery-ui-1.8.23.custom.css" />
<link rel="stylesheet" type="text/css" href="css/form.css" media="all" />
<script src="../jquery-ui-1.8.23.custom/js/jquery-1.8.0.min.js"></script>
<script
    src="../jquery-ui-1.8.23.custom/js/jquery-ui-1.8.23.custom.min.js"></script>

</head>
<h:body>
<form id="form_486588" class="appnitro" method="post">
            <div class="form_description"></div>
            <p:pickList id="pickList" value="#{editorsMB.editors}" var="editor"
                itemLabel="#{editor}" itemValue="#{editor}" />
            <p:commandButton id="citySubmit" value="Submit"
                style="margin-top:5px" />
        </form>
</h:body>
</html>

托管bean
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.model.DualListModel;

@ManagedBean(name = "editorsMB")
@SessionScoped
public class AdminEditorsBean {

    private DualListModel<String> editors;  

    public AdminEditorsBean(){
    List<String> adminsSource = new ArrayList<String>();  
    List<String> adminsTarget = new ArrayList<String>();  

    adminsSource.add("aaa");  
    adminsTarget.add("target1");
    editors = new DualListModel<String>(adminsSource, adminsTarget);  
    }

    public DualListModel<String> getEditors() {  
        return editors;    
}  
    public void setEditors(DualListModel<String> editors) {  
        this.editors = editors;  
    }  

}

最佳答案

PrimeFaces 将在 <h:head> 中自动包含必要的 JS/CSS 资源.

但是,您没有那个标签。你有一个“纯 HTML”<head> .相应地修复它:

<html>
    <h:head>
        ...
    </h:head>
    <h:body>
        ...
    </h:body>
</html>

这个错误也应该记录在服务器日志中,如下所示:

One or more resources has the target of 'head' but not 'head' component has been defined within the view



另见 How to include another XHTML in XHTML using JSF 2.0 Facelets?When to use <ui:include>, tag files, composite components and/or custom components?有关创作 JSF/Facelets 页面的各种正确示例。

无关 具体问题:PrimeFaces 作为一个基于 jQuery 的 JSF 组件库,已经与 jQuery 和 jQuery UI 捆绑在一起。您应该从页面中删除手动包含的脚本以避免冲突。另见 Adding jQuery to PrimeFaces results in Uncaught TypeError over all place .

立即捕获机会替换那个冗长的<link>来自 <h:outputStylesheet> .另见 How to reference CSS / JS / image resource in Facelets template?

关于jsf - PrimeFaces CSS 外观缺失和 JS "Uncaught Reference Error: PrimeFaces is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14553417/

相关文章:

java - 需要在 JSF 中隐藏我的 URL

java - 使用 JSF/PrimeFaces 的观察者模式

excel - 用于大数据的 PrimeFaces DataExporter

jsf-2 - Primefaces 4.0 p :selectOneMenu valueChangeListener

html - 向 JSF 2.0 UIInput 组件添加自定义属性 (HTML5) 支持

jsf - 在 p :fileDownload and hide status when it is finished 开始时显示状态

css - 在标签 p :inputText 中使用属性 moz-transition 和 webkit-transition

jquery - Primefaces - 用于数据表中实时过滤的自定义组件

jsf - 与元素类型 "pt"关联的属性 "pt:data-inset"的前缀 "p:dataList"未绑定(bind)

jsf - 如何更改 <p :calendar> language