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 ...
Edit:
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.
(The code may contain bugs/typos since it is stripped down)
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).
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)
}
}
An example call could be:
loadNodes(tree, $('#j_idt62\\:tree\\:0'));
Where tree
is the WidgetVar of the p:tree
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.