This discussion is archived
6 Replies Latest reply: Oct 2, 2013 3:19 AM by Muddasar Amin RSS

getting tree node value in java bean in ADF

Muddasar Amin Newbie
Currently Being Moderated

Hi, I am trying to get ADF tree node value in java class, the code for the selection Listener class is below, when I click on any node, I am getting Null pointer exception in the highlighted code line.

please help !!!

 

 

 

package com.knm.allapprovals.view.backing;

 

 

import java.util.Iterator;

 

 

import java.util.List;

 

 

import javax.el.ELContext;

import javax.el.ExpressionFactory;

import javax.el.MethodExpression;

 

 

import javax.faces.application.Application;

import javax.faces.context.FacesContext;

 

 

import oracle.adf.view.rich.component.rich.data.RichTree;

 

 

import oracle.adf.view.rich.component.rich.data.RichTreeTable;

 

 

import oracle.jbo.Row;

import oracle.jbo.uicli.binding.JUCtrlHierBinding;

import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;

 

 

import org.apache.myfaces.trinidad.event.SelectionEvent;

import org.apache.myfaces.trinidad.model.CollectionModel;

import org.apache.myfaces.trinidad.model.RowKeySet;

import org.apache.myfaces.trinidad.model.TreeModel;

 

 

public class getNodeValue {

    public getNodeValue() {

    }

 

 

    public void onTreeSelect(SelectionEvent selectionEvent) {

        // Add event code here...

     //   String adfSelectionListener = "#{bindings.Menued1.treeModel.makeCurrent}";

       

        FacesContext fctx = FacesContext.getCurrentInstance();

                Application application = fctx.getApplication();

                ELContext elCtx = fctx.getELContext();

                ExpressionFactory exprFactory = application.getExpressionFactory();

                MethodExpression me = null;

                me =

         exprFactory.createMethodExpression(elCtx, adfSelectionListener, Object.class, new Class[] { SelectionEvent.class });

                me.invoke(elCtx, new Object[] { selectionEvent });

               

                RichTree tree = (RichTree)selectionEvent.getSource();

                TreeModel model = (TreeModel)tree.getValue();

                //get selected nodes

                RowKeySet rowKeySet = selectionEvent.getAddedSet();

                Iterator rksIterator = rowKeySet.iterator();

                while (rksIterator.hasNext()) {

                    List key = (List)rksIterator.next();

                    JUCtrlHierBinding treeBinding = null;

                    treeBinding = (JUCtrlHierBinding)((CollectionModel)tree.getValue()).getWrappedData();

                    JUCtrlHierNodeBinding nodeBinding = treeBinding.findNodeByKeyPath(key);]

 

                   Row rw = nodeBinding.getRow();                                                                      // Null Pointer Exception here

 

                    System.out.println("row: " + rw.getAttribute(0)); // You can get any attribute

                    System.out.println("View Object name---->" + nodeBinding.getViewObject().getName());

 

 

                }

       

        System.out.println("shafia");

    }

}

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points