This discussion is archived
6 Replies Latest reply: Dec 25, 2012 2:44 AM by Pen-Pen RSS

Cast error trying to access tree binding

835970 Newbie
Currently Being Moderated
JDeveloper version 11.1.2.1.0

java.util.ArrayList cannot be cast to oracle.jbo.uicli.binding.JUCtrlHierBinding

Hi All

I'm using code from ADF Code Corner (http://www.oracle.com/technetwork/developer-tools/adf/learnmore/78-man-expanding-trees-treetables-354775.pdf) to try and programmatically set the tree node disclosure level when the page is initially rendered. The tree's DisclosedRowKeys property is set to #{viewScope.FieldPickerHandler.newDisclosedTreeKeys}. The code for the handler method that's causing the problem is below. First you can see that I have commented out Frank's original code on lines 5, 6 & 8 because for some reason this did not find the tree component (always returned null). So instead I have set the tree component's Binding property to #{viewScope.FieldPickerHandler.jsfTree} to make the component instance available in the handler and this seems to work. However when the code hits line 16 I get the class cast exception at the head of this post.

One significant variation from the Code Corner example is that my tree is based on a POJO model that is populated programmatically from a VO (as posted by Lucas Jellema http://technology.amis.nl/blog/2116/much-faster-adf-faces-tree-using-a-pojo-as-cache-based-on-read-only-view-object-showing-proper-leaf-nodes-again) hence my root node set, and each node's child set, is declared as "List<FieldPickerNode> nodes = new ArrayList<FieldPickerNode>();".

Does the way the POJO tree is constructed make it incompatible with the Code Corner node expansion approach? Can anyone suggest how I can modify my handler bean code to work with the POJO tree?

Thanks

Adrian

PS The tree's Value property is set to #{viewScope.FieldPickerHandler.treemodel} where treemodel is a managed property of the bean - I guess this mean my tree is not ADF-bound?

1 public RowKeySetImpl getNewDisclosedTreeKeys() {
2 if (newDisclosedTreeKeys == null) {
3 newDisclosedTreeKeys = new RowKeySetImpl();
4
5// FacesContext fctx = FacesContext.getCurrentInstance();
6// UIViewRoot root = fctx.getViewRoot();
7 //lookup thetree component by its component ID
8// RichTree tree = (RichTree)root.findComponent("t1");
9 //if tree is found ....
10 if (jsfTree != null) {
11 //get the collection model to access the ADF binding layer for
12 //the tree binding used. Note that for this sample the bindings
13 //used by the tree is different from the binding used for the tree
14 //table
15 CollectionModel model = (CollectionModel)jsfTree.getValue();
16 JUCtrlHierBinding treeBinding = (JUCtrlHierBinding)model.getWrappedData();

Edited by: blackadr on 03-Nov-2011 17:56
  • 1. Re: Cast error trying to access tree binding
    Frank Nimphius Employee ACE
    Currently Being Moderated
    Hi,

    java.util.ArrayList cannot be cast to oracle.jbo.uicli.binding.JUCtrlHierBinding


    JUCtrlHierBinding is the tree model binding in ADF, whereas if you don't use ADF for the tree binding, its your Tree model implementatuon, which in your case appears to be an ArrayList. So the code from ADF Code Corner is kind of by passed by your custom implementation. You need to cast it to ArrayList and get the data you want to work with out of this list

    You need to look into what the row key of each node is defined as. This then gives you a hint on how to make the ADF Code Corner sample work for your example.

    Frank

    Ps.: Lucas blog post is kind of old and focuses on 10.1.3
  • 2. Re: Cast error trying to access tree binding
    835970 Newbie
    Currently Being Moderated
    Thanks for clarifying. I was starting to reach that conclusion last night as I lay awake in the small hours thinking about the ADF binding layer (!) - I think this stuff is finally starting to make sense...
  • 3. Re: Cast error trying to access tree binding
    835970 Newbie
    Currently Being Moderated
    Hello Frank et al

    Still struggling valiantly to create a POJO tree that uses the ADF binding layer. Rather than referencing the treemodel directly from the component I have now added a method to my model class that returns the set of root nodes as an ArrayList:

    public List<FieldPickerNode> getRootNodes() {
    if (treemodel == null) {
    treemodel = initializeTreeModel();
    }
    return rootNodes;
    }

    and my FieldPickerNode class also now has a method to return its children as an ArrayList. The model class is managed in view scope. So I drag the rootNodes collection from the Data Controls panel into my panel collection and get the option to create it as an ADF tree. Great. I add the method to get the children as an accessor and the bindings end up looking like this:

    <iterator Binds="root" RangeSize="25" DataControl="FieldPickerModel" id="FieldPickerModelIterator"/>
    <accessorIterator MasterBinding="FieldPickerModelIterator" Binds="rootNodes" RangeSize="25"
    DataControl="FieldPickerModel" BeanClass="view.picker.FieldPickerNode" id="rootNodesIterator"/>

    <tree IterBinding="rootNodesIterator" id="rootNodes">
    <nodeDefinition DefName="view.picker.FieldPickerNode" Name="rootNodes0">
    <AttrNames>
    <Item Value="nodeID"/>
    </AttrNames>
    <Accessors>
    <Item Value="children"/>
    </Accessors>
    </nodeDefinition>
    </tree>

    The tree component looks like this:

    <af:tree value="#{bindings.rootNodes.treeModel}" var="node"
    selectionListener="#{bindings.rootNodes.treeModel.makeCurrent}"
    rowSelection="single" id="t1">
    <f:facet name="nodeStamp">
    <af:outputText value="#{node}" id="ot1"/>
    </f:facet>
    </af:tree>

    To my untrained eye this all seems to look ok but when I run the page I get two null pointer errors in the browser and a couple thousand lines of repeated stack in the log viewer. In the early stages of the log there's a message "<BeanHandler> <getStructure> Failed to build StructureDefinition for : view.picker.FieldPickerModel" which I feel can't be good but is in the depths of the framework so difficult for me to debug (am in the process of requesting the ADF source). I've shown the message below with a few lines of context either side.

    Can you think of any other lines of enquiry I can follow to progress this? For example are there other attributes or methods that I need to add to my tree model classes in order to support the ADF binding?
    For background, the reason I started pursuing the POJO tree in the first place was because for large hierarchies the VO driven tree is unacceptably slow given that it fires SQL for each individual node disclosure. Linking the tree model directly to the component demonstrates just how quick the POJO approach is but I would like to have it go through the ADF bindings so I have more scope to customise the tree behaviour.

    Any pointers or help you (or anyone) can give would be very much appreciated.

    Adrian

    <ADFLogger> <end> Refreshing binding container
    <DCExecutableBinding> <refreshIfNeeded> [40] DCExecutableBinding.refreshIfNeeded(338) Invoke refresh for :rootNodesIterator
    <DCIteratorBinding> <refresh> [41] DCIteratorBinding.refresh(4438) Executing and syncing on IteratorBinding.refresh from :rootNodesIterator
    <ADFLogger> <begin> Instantiate Data Control
    <BeanHandler> <getStructure> Failed to build StructureDefinition for : view.picker.FieldPickerModel
    <MOMParserMDS> <parse> [42] MOMParserMDS.parse(226) No XML file /view/picker/picker.xml for metaobject view.picker.picker
    <MOMParserMDS> <parse> [43] MOMParserMDS.parse(228) MDS error (MetadataNotFoundException): MDS-00013: no metadata found for metadata object "/view/picker/picker.xml"
    <DefinitionManager> <loadParent> [44] DefinitionManager.loadParent(1508) Cannot Load parent Package : view.picker.picker
    <DefinitionManager> <loadParent> [45] DefinitionManager.loadParent(1509) Business Object Browsing may be unavailable
  • 4. Re: Cast error trying to access tree binding
    Frank Nimphius Employee ACE
    Currently Being Moderated
    Hi,

    have a look at sample 38 http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html#CodeCornerSamples

    Frank
  • 5. Re: Cast error trying to access tree binding
    835970 Newbie
    Currently Being Moderated
    Actually I'm already aware of the Code Corner samples. It's the "How-to build an editable tree with the POJO Data Control" I've been using to try and get my tree working. I was hoping you could give more specific guidance based on the detail in my last post...
  • 6. Re: Cast error trying to access tree binding
    Pen-Pen Newbie
    Currently Being Moderated
    i have a problem similiar to this, how did u solve it?

Legend

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