简体   繁体   English

为什么richfaces树的例子不起作用?

[英]Why that richfaces tree example does not work?

Hi I have written a simple example for richfaces tree tag, but it only expands root nodes (but does not collapse them back) the xhtml code: 您好我已经为richfaces树标记编写了一个简单的示例,但它只扩展了根节点(但不会将它们折叠回来)xhtml代码:

   <rich:panel id="unitTest" width="240" height="400">
      <h:form>
      <rich:tree>
         <rich:recursiveTreeNodesAdaptor roots="#{tree.nodes}" var="item" nodes="#{item.nodes}" >
            <rich:treeNode>
               <h:outputText value="#{item}"/>
            </rich:treeNode> 
         </rich:recursiveTreeNodesAdaptor>
      </rich:tree>
      </h:form>
   </rich:panel>

java bean code: java bean代码:

import java.util.*;

public class UnitTreeNode
{
   String name;
   List<UnitTreeNode> children;

   public UnitTreeNode()
   {
      this.name="";
   }
   public UnitTreeNode(String name)
   {
      this.name=name;
   }
   public List<UnitTreeNode> getNodes() 
   {
      if(children==null)
      {
         children=new ArrayList<UnitTreeNode>();
         for(int i=0;i<3;i++)
           children.add(new UnitTreeNode(name+i));
      }
      return children;
   }
   public String toString()
   {
      return name;
   }
}

config: 配置:

   <managed-bean>
      <managed-bean-name>tree</managed-bean-name>
      <managed-bean-class>UnitTreeNode</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
   </managed-bean>

I am using myfaces 1.2.8 and richfaces 3.3.2.SR1, and I cannot see why it does not work. 我使用myfaces 1.2.8和richfaces 3.3.2.SR1,我不明白为什么它不起作用。

The problem is by default tree switchType is ajax and your ajax requests are not getting properly submitted to server due to the surrounding tag.(Seems to be a bug with rich faces implementation and it may be solved with later releases). 问题是默认情况下,树的switchType是ajax,并且由于周围的标记,你的ajax请求没有正确地提交给服务器。(似乎是富脸实现的错误,可能会在以后的版本中解决)。

So here is the solution 所以这是解决方案

  1. use <rich:tree switchType="server"> 使用<rich:tree switchType="server">
  2. or just remove the <h:form> tag 或者只是删除<h:form>标记

Hope this helps 希望这可以帮助

I had the same problem on faces 3.3.3, setting facelets.BUILD_BEFORE_RESTORE to false in my web.xml did it. 我在面部3.3.3上遇到了同样的问题,在我的web.xml中将facelets.BUILD_BEFORE_RESTORE设置为false就可以了。

<context-param>
  <param-name>facelets.BUILD_BEFORE_RESTORE</param-name>
  <param-value>false</param-value>
</context-param>

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

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