JSF更新primefaces树儿 [英] JSF update primefaces tree children

查看:380
本文介绍了JSF更新primefaces树儿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新primefaces树的孩子,而不从服务器拉动整个树。

i want to update the children of the primefaces tree without pulling the whole tree from the server.

我可以更新整个树,但并不一个特定节点的孩子......

I can update the whole tree but not only the children of a specific node ...

编辑:

这是我的code的例子:

This is an example of my code:

<p:tree value="#{cc.tree}" var="wrapper" id="tree" widgetVar="tree" styleClass="commentTree-#{cc.id}">
   <p:treeNode id="treeNode" styleClass="treenode-#{wrapper.id}">
      Hallo: #{wrapper.text}
   </p:treeNode>
</p:tree>

现在我想更新一个特定的树节点。

Now i want to update a specific treenode.

function findIDbySelector(selector) {
    return $(selector).first().attr('id');
}

function updateComponent(clientID) {
    var ajax_json = {};
    ajax_json['source'] = '#{cc.id}';
    ajax_json['update'] = clientID;

    PrimeFaces.ajax.AjaxRequest(ajax_json);
}

[...]

updateComponent(findIDbySelector('.treenode-1'));

正如我所说的,我可以更新整个树,但我只是想更新单个树节点。

As i said i can update the whole tree but i only want to update a single Treenode.

(将code可能包含错误/错别字,因为它剥夺了)

(The code may contain bugs/typos since it is stripped down)

推荐答案

我通过primefaces来源爬了一下,看到它们所支持的是足以让我的孩子们的加载(我可以换节点的contant成面板和更新,它和孩子)。

I crawled a bit through the primefaces sources and saw that they support the loading of the children which is enough for me (i can wrap the contant of the node into a panel and update that and the children).

要更新的孩子们,我修改了primefaces expandnode方式:

To update the children i modified the primefaces expandnode method:

function loadNodes(tree, c) {
    var a = tree;
    if (tree.cfg.dynamic) {
        if (tree.cfg.cache && c.children(".ui-treenode-children").children().length > 0) {
            tree.showNodeChildren(c);
            return
        }
        if (c.data("processing")) {
            PrimeFaces.debug("Node is already being expanded, ignoring expand event.");
            return
        }
        c.data("processing", true);
        var b = {
            source: tree.id,
            process: tree.id,
            update: tree.id,
            formId: tree.cfg.formId
        };
        b.onsuccess = function (j) {
            var g = $(j.documentElement),
                h = g.find("update");
            for (var e = 0; e < h.length; e++) {
                var l = h.eq(e),
                    k = l.attr("id"),
                    f = l.text();
                if (k == a.id) {
                    c.children(".ui-treenode-children").html(f);
                    a.showNodeChildren(c)
                } else {
                    PrimeFaces.ajax.AjaxUtils.updateElement.call(tree, k, f)
                }
            }
            PrimeFaces.ajax.AjaxUtils.handleResponse.call(tree, g);
            return true
        };
        b.oncomplete = function () {
            c.removeData("processing")
        };
        b.params = [{
            name: tree.id + "_expandNode",
            value: a.getRowKey(c)
        }];
        if (tree.hasBehavior("expand")) {
            var d = tree.cfg.behaviors.expand;
            d.call(tree, c, b)
        } else {
            PrimeFaces.ajax.AjaxRequest(b)
        }
    } else {
        tree.showNodeChildren(c);
        tree.fireExpandEvent(c)
    }
}

这是例子调用可以是:

loadNodes(tree, $('#j_idt62\\:tree\\:0'));

其中,是P中的WidgetVar:树

Where tree is the WidgetVar of the p:tree

这篇关于JSF更新primefaces树儿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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