开发者

Why that richfaces tree example does not work?

开发者 https://www.devze.com 2023-02-03 20:15 出处:网络
Hi I have written a simple example for richfaces tree tag, but it only expands root nodes (but does not collapse them back)

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:

   <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:

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.


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).

So here is the solution

  1. use <rich:tree switchType="server">
  2. or just remove the <h:form> tag

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.

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

精彩评论

暂无评论...
验证码 换一张
取 消