Problem with tree tree

Please consider an example of a tree of rich persons:

  <rich:tree switchType="ajax">
<rich:treeNodesAdaptor id="officeNodeAdaptor" nodes="#{officesBean.offices}" var="office" >
      <rich:treeNode changeExpandListener="#{office.loadEmplyeesIfNeeded}" >
          <h:outputText value="#{office.name}" />
      </rich:treeNode>
<rich:treeNodesAdaptor id="employeeNodeAdaptor" nodes="#{office.employees}" var="employee">
       <rich:treeNode>
           <h:outputText value="#{employee.name}" />
       </rich:treeNode>
</rich:treeNodesAdaptor>

This is an example tree for representing the data structure "Offices โ†’ Employees". I want emplyees to load in a lazy way - that's why I introduced loadEmplyeesIfNeeded expand listener. Everything works well, except for one. Employees load after expanding the office node. Therefore, when a tree is displayed, all offices have no employee and are displayed as leaves. And, of course, the leaves cannot be expanded ....

To make a long store short. Is there a way to establish that a node should appear as a node (expandable) despite having no children? It would be best if rich: treeNode had some attribute, for example isNode, but it is not.

b.t.w. , . ...

.

+3
2

, . .

org.richfaces.model.TreeNodeImpl, .

   public class RichTreeNodeImpl extends org.richfaces.model.TreeNodeImpl {

       private boolean treatAsNode;

       public boolean getTreatAsNode() {
         return treatAsNode;
       }

       public void setTreatAsNode(boolean treatAsNode) {
         this.treatAsNode = treatAsNode;
       }

       @Override
       public boolean isLeaf() {
           if (this.treatAsNode)
              return false;
           else
              return super.isLeaf();
       }
   }
+4

, OpenFaces TreeTable, . , preloadedNodes = "none" ( prelodedNodes = "levelsPreloaded: 1" ) <o:treeTable>, , node. OpenTaces TreeTable , , (, . )

TreeTable ( , ):

<o:treeTable var="node" preloadedNodes="none">
  <o:dynamicTreStructure nodeChildren="#{treeTableBean.nodeChildren}"/>
  <o:treeColumn>
    <h:outputText value="node.name"/>
  </o:treeColumn>
</o:treeTable>

treeTableBean.nodeChildren "node" ( , NULL). :

public List getNodeChildren() {
  Object node = Faces.var("node");
  if (node == null) 
    return getOffices();
  else
    return ((Office) node).getEmployees();
}
+2

Source: https://habr.com/ru/post/1776874/


All Articles