未捕获的TypeError:无法在primefaces.js中调用null的方法``删除''?ln = primefaces [英] Uncaught TypeError: Cannot call method 'remove' of null in primefaces.js?ln=primefaces

查看:115
本文介绍了未捕获的TypeError:无法在primefaces.js中调用null的方法``删除''?ln = primefaces的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示一个选择树形视图,您应该在其中选择一个新项目将在Primefaces 3.3.1/JSF 2.0下进入哪个文件夹.到目前为止,我已经在树中填充了文件夹和子文件夹:

I'm trying to display a single selection treeview where you're supposed to select which folder a new item will go under with Primefaces 3.3.1/JSF 2.0. So far, I have populated the tree with folders and subfolders:

但是,当我尝试选择文件夹时,什么也没发生.我的.xhtml页面看起来像这样:

But, when I try to select a folder: nothing happens. My .xhtml page looks like this:

<h:form id="createSiteForm">
    <label>Under vilken mapp ska sidan ligga under: </label><br />
    <p:tree id="treeSingle" value="#{siteBean.root}" var="node"  
            selectionMode="single"  
            selection="#{siteBean.selectedNode}" dynamic="true" cache="false">  

        <p:treeNode>  
            <h:outputText value="#{node}" />
        </p:treeNode>  
    </p:tree>
</h:form>

还有我的managed bean:

@ManagedBean(name = "siteBean")
@RequestScoped
public class SiteBean implements Serializable {

    private TreeNode root;
    private TreeNode selectedNode;

    public SiteBean(){
        this.loadTreeNodes();
    }

    @SuppressWarnings("rawtypes")
    public void loadTreeNodes(){
        try {
            WebDB db = new WebDB();

            List<Folder> folders = db.getRootFolders();
            root = new DefaultTreeNode("Root", null); 
            boolean first = true;

            db = null;

            for (Iterator fi = folders.iterator(); fi.hasNext();){
                Folder folder = (Folder) fi.next();

                TreeNode node = new DefaultTreeNode(folder.getName(), root);

                if(first){
                    node.setSelected(true);
                    selectedNode = node;
                    first = false;
                }

                this.findNodeChildren(folder.getId(), node);
            }

        } catch (DatabaseException e) {
            e.printStackTrace();
        }
    }

    @SuppressWarnings("rawtypes")
    private void findNodeChildren(Long id, TreeNode parent){

        try {
            WebDB db = new WebDB();

            List<Folder> fChildren = db.getFolderChildren(id);

            db = null;

            if(fChildren != null && fChildren.size() > 0){

                for (Iterator fi = fChildren.iterator(); fi.hasNext();){
                    Folder folder = (Folder) fi.next();

                    TreeNode node = new DefaultTreeNode(folder.getName(), parent);  

                    this.findNodeChildren(folder.getId(), node);
                }
            }

        } catch (DatabaseException e) {
            e.printStackTrace();
        }
    }

    public TreeNode getRoot() {  
        return root;  
    }  

    public TreeNode getSelectedNode() {  
        return selectedNode;  
    }  

    public void setSelectedNode(TreeNode selectedNode) {  
        this.selectedNode = selectedNode;  
    }
}

然后我得到一个奇怪的jQuery错误:primefaces.js?ln=primefaces中的Uncaught TypeError: Cannot call method 'remove' of null.我找不到有关此错误的任何信息:S

And I get this strange jQuery error: Uncaught TypeError: Cannot call method 'remove' of null in primefaces.js?ln=primefaces. I can't find any information about this error :S

推荐答案

然后我收到一个奇怪的jQuery错误:Uncaught TypeError:无法在primefaces.js?ln = primefaces中调用null的方法删除".

这类jQuery错误通常是由网络应用加载的重复版本不同的jQuery JS文件引起的. PrimeFaces作为基于jQuery的JSF组件库,已经可以自动自动加载jQuery.这个问题表明您出于某种原因要通过<script>/<h:outputScript>手动在PrimeFaces顶部手动加载另一个jQuery JS文件.如果删除它们,则此错误应消失.

Those kind of jQuery errors are typically caused by having duplicate different versioned jQuery JS files loaded by the webapp. PrimeFaces as being a jQuery-based JSF component library already automatically loads jQuery by itself. This problem suggests that you're for some reason manually loading another jQuery JS file yourself on top of PrimeFaces one via <script>/<h:outputScript>. If you remove them, then this error should disappear.

如果您碰巧要在其中使用某些jQuery的页面,但是该页面本身未使用任何PrimeFaces组件,因此不一定会自动加载与PrimeFaces捆绑的jQuery,那么您始终可以显式只需添加以下行即可自己加载它:

If you happen to have a page wherein you'd like to use some jQuery, but the page itself doesn't utilize any PrimeFaces component and thus doesn't necessarily have PrimeFaces-bundled jQuery automatically loaded, then you can always explicitly load it yourself by simply adding the following line:

<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />

这将显式加载PrimeFaces库捆绑的jQuery文件.注意:target="head"已经在<h:head>内部时,可以省略.否则,例如在模板客户端的<h:body><ui:define>中时,它将自动重新定位到head.另一个注意事项:您可以在实际上需要PrimeFaces捆绑的jQuery的页面中安全地使用此行.它不会以繁琐的负载结束.

This will explicitly load the PrimeFaces library-bundled jQuery file. Note: the target="head" can be omitted when it's already inside the <h:head>. Otherwise, e.g. when inside <h:body> or <ui:define> of a template client, it would be automatically relocated to head. Another note: you can safely use this line in a page which actually requires PrimeFaces-bundled jQuery. It won't end up in a duplciate load.

这篇关于未捕获的TypeError:无法在primefaces.js中调用null的方法``删除''?ln = primefaces的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆