如何获取PrimeFaces树节点的根?
我有一个html页面,它从控制器获取一个树节点如何获取PrimeFaces树节点的根?,primefaces,tree,Primefaces,Tree,我有一个html页面,它从控制器获取一个树节点 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:c="http://java.sun.com/jsp/jstl/core"> <ui:composition> <pa:pan
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:composition>
<pa:panelTree styleClass="corps-grade-list"
treeContent="#{affectationController.getDossierEnBrefAffectations()}"
rendered="#{agentModele.estMigre}" />
</ui:composition>
</html>
因此,affectationController.getdossierenbreaffections()
是一个返回此树节点的函数。我想获取此树的根节点
我尝试了
treeContent=“${affectationControleur.ConsulterDossierefEffections.children[0]}”
,因为TreeNode类具有该函数。但是,它不是EL的正确语法。如果您没有扩展DefaultTreeNode
类或实现接口,请这样做。现在,您只需将此方法添加到树节点实现中:
public TreeNode getRoot() {
if (getParent() == null) {
return this;
}
TreeNode root = getParent();
while (root.getParent() != null) {
root = root.getParent();
}
return root;
}
这允许您使用:#{bean.treeNode.root}
如果无法更改模型,可以在bean中添加类似的内容:
public TreeNode getRoot(TreeNode node) {
if (node.getParent() == null) {
return node;
}
TreeNode root = node.getParent();
while (root.getParent() != null) {
root = root.getParent();
}
return root;
}
这允许您使用:
#{bean.getRoot(treeNode)}
如果您没有扩展DefaultTreeNode
类或实现接口,请这样做。现在,您只需将此方法添加到树节点实现中:
public TreeNode getRoot() {
if (getParent() == null) {
return this;
}
TreeNode root = getParent();
while (root.getParent() != null) {
root = root.getParent();
}
return root;
}
这允许您使用:#{bean.treeNode.root}
如果无法更改模型,可以在bean中添加类似的内容:
public TreeNode getRoot(TreeNode node) {
if (node.getParent() == null) {
return node;
}
TreeNode root = node.getParent();
while (root.getParent() != null) {
root = root.getParent();
}
return root;
}
这允许您使用:#{bean.getRoot(treeNode)}