简体   繁体   English

富面临树问题

[英]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. 我希望以懒惰方式加载emplyees - 所以我介绍了loadEmplyeesIfNeeded扩展监听器。 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.. 最好的是如果富有:treeNode会有一些像isNode那样的属性,但它不会...

btw 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. 在此先感谢您的帮助。

A little late but. 有点晚了但是。 Who knows. 谁知道。

You can extend org.richfaces.model.TreeNodeImpl as I did. 您可以像我一样扩展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();
       }
   }

You can do this using OpenFaces TreeTable if you don't mind adding another library to your application. 如果您不介意在应用程序中添加其他库,则可以使用OpenFaces TreeTable执行此操作。 Lazy loading can be implemented just by adding the preloadedNodes="none" (or prelodedNodes="levelsPreloaded:1") to <o:treeTable> tag, and it will also automatically detect whether the node's expansion toggle should be displayed. 只需将preloadedNodes =“none”(或prelodedNodes =“levelsPreloaded:1”)添加到<o:treeTable>标记即可实现延迟加载,它还将自动检测是否应显示节点的扩展切换。 OpenFaces TreeTable is quite customizable and it shouldn't necessarily look as a multi-column table, but it can be shown as a simple tree as well (eg see this page ) OpenFaces TreeTable是可以自定义的,它不一定看起来像一个多列表,但它也可以显示为一个简单的树(例如,见本页

Here's how such a TreeTable can be declared (you might actually need more customizations, but this example shows the idea): 以下是如何声明这样的TreeTable(您可能实际上需要更多自定义,但此示例显示了这个想法):

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

The treeTableBean.nodeChildren method should take the value of the "node" variable, and return its child nodes (or return root nodes if its value is null). treeTableBean.nodeChildren方法应该取“node”变量的值,并返回其子节点(如果其值为null,则返回根节点)。 Here's how this method might look in your case: 以下是此方法在您的情况下的外观:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM