0 Replies Latest reply on Jul 27, 2009 1:37 PM by L Kr

    rich:tree reRender and d'n'd-support problems

    L Kr Newbie

      Hi,

      I'm having a rich:tree with a nodeSelectListener and a dropListener. The tree itself works fine but when I click on a node I would like to display different forms based on the selected node. The tree is located on the left side of my page and the submit form should be displayed on the right side of the form. While the event handler is called correctly - the form is not displayed (the request is executed but the controller methods are only called once when the whole page is loaded ).

      treeview.xhtml:

      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:t="http://myfaces.apache.org/tomahawk"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:a4j="http://richfaces.org/a4j">
      
      <ui:composition template="layout-2-col.xhtml">
      ...
      <a4j:region renderRegionOnly="true">
      
      <rich:tree
       id="plantTree"
       dragIndicator="indicator"
       switchType="client"
       treeNodeVar="treeNode"
       rowKeyVar="treeRowKey"
       ajaxSubmitSelection="true"
       nodeSelectListener="#{plantTreeViewController.processTreeSelection}"
       dropListener="#{plantTreeViewController.processTreeDrop}">
       <rich:recursiveTreeNodesAdaptor
       roots="#{plantTreeViewController.rootNode}" var="node"
       nodes="#{node.children}">
       <rich:treeNode
       dragType="#{node.componentType}"
       acceptedTypes="GAK">
       <rich:toolTip>
       <span style="white-space: nowrap">
       <h:outputText value="#{node.displayComponentType}" />
       </span>
       </rich:toolTip>
       <h:outputText value="#{node.displayName}"></h:outputText>
       <rich:dndParam name="label" type="drag"
       value="#{node.displayName}" />
       </rich:treeNode>
      </rich:recursiveTreeNodesAdaptor>
      </rich:tree>
      
      
      <a4j:form ajaxSubmit="true">
      <t:panelGrid id="plantNode"
      rendered="#{plantTreeViewController.plantNode}" columns="2" >
      <t:outputLabel
       id="label_plantnode_plantname"
       styleClass="text"
       for="field_accountdata_login"
       forceId="true"
       value="#{bundle['plantnode.plantname']}" />
      
      <t:inputText id="field_plantnode_plantname"
       styleClass="text"
       forceId="true"
       value="#{plantTreeViewController.plant.plantName}"
       required="true">
      </t:inputText>
      </t:panelGrid>
      </a4j:form>
      
      </a4j:region>
      


      plantTreeViewController:
       public void processTreeSelection(NodeSelectedEvent event) {
       System.out.println("processTreeSelection");
       HtmlTree tree = (HtmlTree) event.getComponent();
       System.out.println("tree:"+tree);
       this.rowData = (ComponentTreeNode) tree.getRowData();
       System.out.println("rowData:"+rowData);
       }
      
       public void processTreeDrop(DropEvent dropEvent) {
       System.out.println("processTreeDrop");
       Draggable draggableSource = dropEvent.getDraggableSource();
       System.out.println("draggableSource:"+draggableSource);
       UITreeNode srcNode = (UITreeNode)draggableSource;
       System.out.println("srcNode:"+srcNode);
      
       UITree srcTree = srcNode.getUITree();
       TreeRowKey<?> dragNodeKey = (TreeRowKey<?>) dropEvent.getDragValue();
       TreeNode<?> dragTreeNode = srcTree.getTreeNode(dragNodeKey);
       System.out.println("dragTreeNode:"+dragTreeNode);
      
       TreeNode<?> dragModelTreeNode = srcTree.getModelTreeNode();
       System.out.println("dragModelTreeNode:"+dragModelTreeNode);
      
       getAjaxContext().addComponentToAjaxRender(srcTree);
       }
      


      So, does anybody know what I'm doing wrong ?

      And my second problem with the same tree:
      How can I get the source (dragged) node and the target (dropped) node of a d'n'd operation ? The local variables dragTreeNode and dragModelTreeNode in the above event handler (processTreeDrop) are always null. Very often I even get the following error:

      tree:org.richfaces.component.html.HtmlTree@ef854c
      27.07.2009 17:25:30 com.sun.faces.lifecycle.UpdateModelValuesPhase execute
      WARNUNG: /presentation/plant_treeview.xhtml @45,75 nodeSelectListener="#{plantTreeViewController.processTreeSelection}": java.lang.IllegalStateException: No tree element available or row key not set!
      


      The event handler is still executing furthermore - but with no effect. I'm using rich-faces 3.3.1. In 3.3.0 the above code worked fine - but I did't used the rich:recursiveTreeNodesAdaptor component. Could that be the problem ? Should the node classes implement the org.richfaces.model.TreeNode interface ? For now I'm just using POJO's.

      Thank you
      Lothar