简体   繁体   English

如何隐藏Richfaces树中的某些节点(不按条件渲染节点)?

[英]How to hide some nodes in Richfaces Tree (do not render nodes by condition)?

I have a tree of categories and courses in my SEAM application. 我的SEAM应用程序中有类别和课程的树。 Courses may be active and inactive. 课程可能是活跃的也可能是非活跃的。 I want to be able to show only active or all courses in my tree. 我希望能够仅显示树中的当前课程或所有课程。

I've decided to always build complete tree in my PAGE scope component since building this tree is quite expensive operation. 我决定始终在PAGE范围组件中构建完整的树,因为构建此树是相当昂贵的操作。 I have boolean flag courseActive in the data wrapped by TreeNode<T>. 我在TreeNode <T>包装的数据中具有布尔标志courseActive。 Now I can't find the way to show courses node only if this flag is true. 现在,仅当此标志为true时,我才能找到显示课程节点的方法。

The best result I've achieved with the following code: 我用以下代码实现了最好的结果:

<h:outputLabel for="showInactiveCheckbox" value="show all courses: "/>
<h:selectBooleanCheckbox id="showInactiveCheckbox" value="#{categoryTreeEditorModel.showAllCoursesInTree}">
   <a4j:support event="onchange" reRender="categoryTree"/>
</h:selectBooleanCheckbox>

<rich:tree id="categoryTree" value="#{categoryTree}" var="item" switchType="ajax"
           ajaxSubmitSelection="true" reRender="categoryTree,controls"
           adviseNodeOpened="#{categoryTreeActions.adviseRootOpened}"
           nodeSelectListener="#{categoryTreeActions.processSelection}"
           nodeFace="#{item.typeName}">

   <rich:treeNode type="Category" icon="..." iconLeaf="...">
      <h:outputText value="#{item.title}"/>
   </rich:treeNode>

   <rich:treeNode type="Course" icon="..." iconLeaf="..."
                  rendered="#{item.courseActive or categoryTreeEditorModel.showAllCoursesInTree}">
      <h:outputText rendered="#{item.courseActive}" value="#{item.title}"/>
      <h:outputText rendered="#{not item.courseActive}" value="#{item.title}" style="color:#{a4jSkin.inactiveTextColor}"/>
   </rich:treeNode>

</rich:tree>

the only problem is if some node is not listed in any rich:treeNode it just still shown with title obtained by Object.toString() method insted of being hidden. 唯一的问题是,如果某个节点未在任何rich:treeNode中列出,那么它仍然会显示,而其标题是由Object.toString()方法获得的,而实际上是被隐藏了。

Does anybody know how to not show some nodes in the Richfases tree according to some condition? 有人知道如何根据某种条件不显示Richfases树中的某些节点吗?

Update 更新资料

For better understanding what I'm trying to do I can provide simple example: 为了更好地理解我要做什么,我可以提供简单的示例:

Imagune that I have a filesystem with files and directories and there are normal and hidden files (in my case I have no hidden directories but it's not important). 想象一下,我有一个包含文件和目录的文件系统,并且有普通文件和隐藏文件(在我的情况下,我没有隐藏目录,但这并不重要)。

I want to read files and directories once and store the tree in the model (org.richfaces.model.TreeNode) and then be able to show only directories on one page and only directories and not hidden files by default on another page with possibility to show all files and directories using checkbox on this page. 我想一次读取文件和目录,并将树存储在模型(org.richfaces.model.TreeNode)中,然后能够仅在一个页面上显示目录,而在另一页面上仅显示目录,默认情况下不显示隐藏文件,并且有可能使用此页面上的复选框显示所有文件和目录。

There is not enough to hede(/not render) rish:treeNode element in facelet since if there is a node which is not mentioned in any of rendered rich:treeNode this node is rendered using default icons and title. facelet中没有足够的hede(/未渲染)rish:treeNode元素,因为如果存在任何渲染的rich:treeNode中未提及的节点,则使用默认图标和标题来渲染该节点。 One may think about rich:treeNode like about an elemnt only to add custom visual style to nodes of some types but not as an element responsible for rendering of a node. 可能会想到rich:treeNode就像一个元素一样,只是将自定义视觉样式添加到某些类型的节点上,而不是作为负责渲染节点的元素。

I'm really not sure, but maybe you could try to use a Facelets . 我确实不确定,但是也许您可以尝试使用Facelets。 Would the EL would be evaluated correctly, since c:if is a build-time tag? 由于c:if是构建时标签,EL是否将被正确评估?

See: http://wiki.java.net/bin/view/Projects/FaceletsFAQ#Why_doesn_t_my_c_if_ui_repeat_ui 请参阅: http//wiki.java.net/bin/view/Projects/FaceletsFAQ#Why_doesn_t_my_c_if_ui_repeat_ui

Have you tried the <s:fragment> ? 您是否尝试过<s:fragment>

<s:fragment rendered="#{item.flag == 'true'}">
    Show some stuff here when flag returns true
</s:fragment>

<s:fragment rendered="#{not item.flag}">
    Show some stuff here when flag is NOT true
</s:fragment>

Update 更新资料

I am not sure what your question really is, however I am guessing you want to hide a treenode In your example it would look like this: 我不确定您的问题到底是什么,但是我猜您想隐藏一个treenode在您的示例中,它看起来像这样:

<s:fragment rendered="#{item.courseActive}">
   <rich:treeNode type="Category" icon="..." iconLeaf="...">
      <h:outputText value="#{item.title}"/>
   </rich:treeNode>
</s:fragment>

<s:fragment rendered="#{not item.courseActive}">
  <rich:treeNode type="Course" icon="..." iconLeaf="...">
     <h:outputText value="#{item.title}"/>
  </rich:treeNode>
</s:fragment>

It looks like there are two ways to solve my problem. 看来有两种方法可以解决我的问题。

First one: I can use rich:recursiveTreeNodesAdaptor and in my recursive getter function I can skip some nodes. 第一个:我可以使用rich:recursiveTreeNodesAdaptor,在我的递归getter函数中,我可以跳过一些节点。 This aproach may be hard to use with drag and drop for moving items in the tree. 通过拖放来移动树中的项目可能很难使用此方法。

Second one: Attach detach some nodes on the server side. 第二个: Attach分离服务器端的一些节点。 Disadvantage of this approach is a lot of Java code for recursive iterations through the tree. 这种方法的缺点是很多Java代码用于树的递归迭代。

I think I'll use the second way since I need drag and drop tree editor. 我想我将使用第二种方法,因为我需要拖放树编辑器。

The same question was discussed in the JBoss comunity forum one year ago: http://community.jboss.org/message/64929 and the second way was also advised 一年前,在JBoss社区论坛中讨论了相同的问题: http//community.jboss.org/message/64929,并且还建议了第二种方法

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

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