Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get selected child of the Programmatically create treetable (using pojo )

Sardar NaleMar 17 2016 — edited Mar 18 2016

Hi All,

I am using jdeveloper version 11.1.1.6.0.

I have popuplated tree table using Pojo Class. It does contains the Parent->Child in tree table. We need the value of the row of Child which is selected.

Please find the below code for the same:

JSPX Page :

        <af:treeTable rowBandingInterval="0" id="tt1"

                      value="#{pageFlowScope.ProgrammaticTreeTabBean.charatcerVal}" var="node"

                      rowSelection="single" initiallyExpanded="true"

                    

                      binding="#{pageFlowScope.ProgrammaticTreeTabBean.tblModelBind}">

                    <f:facet name="nodeStamp">

                        <af:column headerText="Node Stamp" id="c1" width="250">

                            <af:outputText value="#{node.name}" id="ot1" inlineStyle="font-weight:bold;"/>

                        </af:column>

                    </f:facet>

        </af:treeTable>

Java Code :

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

import javax.faces.event.ActionEvent;

import javax.faces.event.PhaseEvent;

import oracle.adf.model.bean.DCDataRow;

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

import oracle.adf.view.rich.context.AdfFacesContext;

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.ChildPropertyTreeModel;

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

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

public class ProgrammaticTreeTabBean {

    List<Seasons> seasonList = new ArrayList<Seasons>();

    ChildPropertyTreeModel charatcerVal;

    private RichTreeTable tblModelBind;

    public ProgrammaticTreeTabBean() {

        super();

        // Creating tree for Seasons and Characters details

        // Adding Master Values (seasons)

        Seasons season1 = new Seasons("Game of Thrones");

       // Adding Detail Values (Child Node-Characters)

        Seasons character = new Seasons("Tywin Lannister");

        season1.addCharaters(character);

        character = new Seasons("Tyrion Lannister");

        season1.addCharaters(character);

        character = new Seasons("Jaime Lannister");

        season1.addCharaters(character);

        character = new Seasons("Cersie Lannister");

        season1.addCharaters(character);

        character = new Seasons("Ned Stark");

        season1.addCharaters(character);

        // Adding Master Values (seasons)

        Seasons season2 = new Seasons("Arrow");

        // Adding Detail Values (Child Node-Characters)

        character = new Seasons("Oliver Queen");

        season2.addCharaters(character);

        character = new Seasons("Moira Queen");

        season2.addCharaters(character);

        character = new Seasons("Laurel Lance");

        season2.addCharaters(character);

        character = new Seasons("Sara Lance");

        season2.addCharaters(character);

        // Adding Master Values (seasons)

        Seasons season3 = new Seasons("Vikings");

      // Adding Detail Values (Child Node-Characters)

        character = new Seasons("Ragnar Lothrak");

        season3.addCharaters(character);

        // Adding all list to topList

        seasonList.add(season1);

        seasonList.add(season2);

        seasonList.add(season3);

        // Filtering Child Data, ChildPropertyTreeModel creates a TreeModel from a List of beans, see

        // https://myfaces.apache.org/trinidad/trinidad-api/apidocs/org/apache/myfaces/trinidad/model/ChildPropertyTreeModel.html

        charatcerVal = new ChildPropertyTreeModel(seasonList, "characters");

    }

    public ChildPropertyTreeModel getCharatcerVal() {

        return charatcerVal;

    }

    public void rowSelectionListener(SelectionEvent selectionEvent) {

       

        //get selected nodes

           RowKeySet rowKeySet = selectionEvent.getAddedSet();

           Iterator<Object> rksIterator = (Iterator<Object>)rowKeySet.iterator();

           //for single select configurations,this only is called once

           while (rksIterator.hasNext()) {

               List<Object> key = (List<Object>)rksIterator.next();

               JUCtrlHierBinding treeBinding = null;

               CollectionModel collectionModel = (CollectionModel)tblModelBind.getValue();

               treeBinding = (JUCtrlHierBinding)collectionModel.getWrappedData();

               JUCtrlHierNodeBinding nodeBinding = null;

               nodeBinding = treeBinding.findNodeByKeyPath(key);

               Row rw = nodeBinding.getRow();

               //print first row attribute. Note that in a tree you have to

               //determine the node type if you want to select node attributes

               //by name and not index

               String rowType = rw.getStructureDef().getDefName();

      

            }

    }

    public void setTblModelBind(RichTreeTable tblModelBind) {

        this.tblModelBind = tblModelBind;

    }

    public RichTreeTable getTblModelBind() {

        return tblModelBind;

    }

   

}

At the line treeBinding = (JUCtrlHierBinding)collectionModel.getWrappedData();  in method rowSelectionListener it says Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to oracle.jbo.uicli.binding.JUCtrlHierBinding

Please suggest any way to get the selected child value.

This post has been answered by Sardar Nale on Mar 18 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 15 2016
Added on Mar 17 2016
3 comments
395 views