3 Replies Latest reply on Sep 22, 2013 11:38 PM by ashu17

    Richfaces 4.3.1 Final <rich:tree> getRowData() is null . Rest attributes are populating fine.

    ashu17

      I have used AuditTreeNode and extended TreeNodeImpl to iterate tree. But rowData is null in backing bean.So I am not able to get name of selected node/leaf. Here is code snippet

       

      =================AuditTreeNode=======================

       

       

      import java.util.Enumeration;

      import javax.swing.tree.TreeNode;

      import org.richfaces.model.TreeNodeImpl;

       

      public class AuditTreeNode extends TreeNodeImpl {

        private String name;

        private AuditTreeNode rowData;

        private boolean lastnode;

       

        public String getName() {

        return name;

        }

       

        public void setName(String name) {

        this.name = name;

        }

       

        public String toString() {

        return this.name;

        }

       

       

        public Enumeration children() {

        // TODO Auto-generated method stub

        return null;

        }

       

        public boolean getAllowsChildren() {

        // TODO Auto-generated method stub

        return false;

        }

       

        public TreeNode getChildAt(int arg0) {

        // TODO Auto-generated method stub

        return null;

        }

       

        public int getChildCount() {

        // TODO Auto-generated method stub

        return 0;

        }

       

        public int getIndex(TreeNode arg0) {

        // TODO Auto-generated method stub

        return 0;

        }

       

        public TreeNode getParent() {

        // TODO Auto-generated method stub

        return null;

        }

        @Override

        public boolean isLeaf() {

        // TODO Auto-generated method stub

        return this.lastnode;

        }

       

        public void setLastnode(boolean lastnode) {

        this.lastnode = lastnode;

        }

       

        public AuditTreeNode getRowData() {

        return rowData;

        }

       

        public void setRowData(AuditTreeNode rowData) {

        this.rowData = rowData;

        }

      }

      ============================================

       

      ==========Backing Bean ==============

      //method called after selection is made

      public void processSelection(TreeSelectionChangeEvent event)

        throws AbortProcessingException {

        UITree tree = (UITree) event.getComponent();

        this.auditType = tree.getRowData().toString();

      .............

      .............

        selectedNodeChildren.clear();

        }

       

      //Method to populate tree object

      private AuditTreeNode populateAuditTypeTree() {

        final String _methodName = "populateAuditTypeTree";

        if (Log.ON) {

        log.entering(CLASS_NAME, _methodName);

        }

        this.auditTypeTree = new AuditTreeNode();

       

       

        int counter = 0;

        if (auditTypeVOLst != null)

        for (AuditTypeVO auditTypeDTO : auditTypeVOLst) {

        if (auditTypeDTO.getParentId() == null

        || auditTypeDTO.getParentId() == 0) {

       

       

        AuditTreeNode rootNodes = new AuditTreeNode();

        rootNodes.setName(auditTypeDTO.getName());

        this.auditTypeTree.addChild(counter, rootNodes);

        counter++;

      // To process child nodes

        fetchAuditTypeChildrens(auditTypeDTO.getIdPk(),

        auditTypeVOLst, rootNodes);

        }

        }

        if (Log.ON) {

        log.exiting(CLASS_NAME, _methodName);

        }

        return auditTypeTree;

        }

        private void fetchAuditTypeChildrens(long idPk,

        List<AuditTypeVO> auditTypeList, AuditTreeNode rootNodes) {

        int i = 0;

        for (AuditTypeVO auditTypeDTO : auditTypeVOLst) {

        if (auditTypeDTO.getParentId() != null

        && idPk == auditTypeDTO.getParentId()) {

        AuditTreeNode child = new AuditTreeNode();

       

        child.setName(auditTypeDTO.getName());

        rootNodes.setLastnode(false);

        rootNodes.addChild(i, child);

        i++;

        fetchAuditTypeChildrens(auditTypeDTO.getIdPk(), auditTypeVOLst,

        child);

        } else {

        rootNodes.setLastnode(true);

        }

        }

      ==============================

       

      ============UI==================

      <ui:composition 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:rich="http://richfaces.org/rich"

        xmlns:a4j="http://richfaces.org/a4j"

        xmlns:c="http://java.sun.com/jstl/core">

       

       

        <rich:popupPanel id="auditTypeTree" resizeable="false" height="420" header="Audit Type" autosized="true"

        width="400" styleClass="customModalClass">

       

        <f:facet name="controls">

        <h:graphicImage value="/images/ico_close.gif"

        onclick="#{rich:component('auditTypeTree')}.hide();"

        style="cursor:pointer;cursor:hand">

        </h:graphicImage>

        </f:facet>

        <h:form>

        <a4j:region>

        <rich:tree value="#{auditBean.auditTypeTree}" var="item"  rendered="#{auditBean.auditPlanningEditable}"

        id="auditTypeTree2" render="auditType,auditClassificationTree,classificationId"

        toggleType="client"  selectionType="ajax" rowKeyConverter="org.richfaces.IntegerSequenceRowKeyConverter"

        onselectionchange="#{rich:component('auditTypeTree')}.hide();">

        <rich:treeSelectionChangeListener listener="#{auditBean.processSelection}"/>

        <rich:treeNode>

        <h:outputText value="#{item}" />

        </rich:treeNode>

        </rich:tree>

       

        </a4j:region>

        </h:form>

        </rich:popupPanel>

       

      </ui:composition>

      ========================