Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rich faces tree problem

Please consider following rich faces tree example:

  <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 sample tree for representing "Offices --> Employees" data structure. I want to have emplyees loaded in lazy way - so I introduced the loadEmplyeesIfNeeded expand listener. Everything works well except one thing. The employees are loaded after the office node is expanded.. So when the tree is rendered all offices don't have any employee and are rendered as leafs.. And of course leafs can not be expanded....

To make long store short. Is there any way to set that the node should be rendered as node (with possibility to expand) despite having no children? The best would be if rich:treeNode would have some attribut like isNode but it doesn't..

b.t.w. I could solve it by just adding to every office an fake employee at the initialization of offices.. But that's not very nice work around...

Thanks in advance for help.

like image 252
MrFish Avatar asked Nov 29 '25 17:11

MrFish


1 Answers

A little late but. Who knows.

You can extend org.richfaces.model.TreeNodeImpl as I did.

   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();
       }
   }
like image 97
besc Avatar answered Dec 02 '25 08:12

besc