PrimeFaces CSS看起来没什么感觉缺失和JS"未捕获参考错误:PrimeFaces未定义"

use*_*917 5 jsf primefaces

我正在尝试使用Primefaces的Picklist.呈现页面时,Chrome中的javascript引擎无法找到Primefaces对象.我收到以下错误'Uncaught ReferenceError:PrimeFaces未定义'.我错过了在我的.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>
Run Code Online (Sandbox Code Playgroud)

管理豆

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;  
    }  

}
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 26

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

但是,您没有该标签.你有一个"纯HTML" <head>.相应修复:

<html>
    <h:head>
        ...
    </h:head>
    <h:body>
        ...
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

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

一个或多个资源的目标是"head",但未在视图中定义"head"组件

另请参阅如何使用JSF 2.0 Facelets在XHTML中包含另一个XHTML?并且当使用的<ui:包括>,标记文件,复合材料部件和/或定制的组件?有关创作JSF/Facelets页面的各种正确示例.


具体问题无关:PrimeFaces作为一个基于jQuery的JSF组件库已经捆绑了jQuery和jQuery UI.您应该从页面中删除手动包含的脚本以避免冲突.另请参阅向PrimeFaces添加jQuery会导致所有位置出现未捕获的TypeError.

立即抓住机会<link>用a 替换那个冗长的<h:outputStylesheet>.另请参见如何在Facelets模板中引用CSS/JS /图像资源?


归档时间:

查看次数:

19164 次

最近记录:

9 年,7 月 前