Get tree selected node onPageLoad

We just turned on change persistence to keep our row selections as we traverse our taskflows and pages.
In one of our pages we have a situation where we have a tree (master) and table (table) whose data is partially based on what is selected in that tree. We use the following logic to determine what is selected in the tree to perform the query on the table.
public static JUCtrlHierNodeBinding getTreeSelectedNode(RichTree tree) {
JUCtrlHierNodeBinding node = null;
if (tree != null) {
Object oldRowKey = tree.getRowKey();
try {
RowKeySet selectedRowKeySet = tree.getSelectedRowKeys();
if (selectedRowKeySet != null) {
for (Object selectedRowKey : selectedRowKeySet) {
tree.setRowKey(selectedRowKey);
node = (JUCtrlHierNodeBinding)tree.getRowData();
break;
} finally {
tree.setRowKey(oldRowKey);
return node;
I hooked up a beforePhase listener on my jspx to call this function and get the (previously - last time user was on this page) selected row and then refresh the table based on the selected tree row's data. This seems to work, but . . . in my log I'm seeing the following error. It seems like for some reason it's trying to convert my Raw UUID to an int, I have no idea why.
<SortableModel> <_toRowIndex> Invalid rowkey:oracle.jbo.Key[B68F305BF7F5496D8A0FF99EE8F97CF0 ] type:class oracle.jbo.Key
<SortableModel> <_toRowIndex>
java.lang.ClassCastException: oracle.jbo.Key cannot be cast to java.lang.Integer
at org.apache.myfaces.trinidad.model.SortableModel._toRowIndex(SortableModel.java:341)
at org.apache.myfaces.trinidad.model.SortableModel.setRowKey(SortableModel.java:137)
at org.apache.myfaces.trinidad.model.ChildPropertyTreeModel._setRowKey(ChildPropertyTreeModel.java:376)
at org.apache.myfaces.trinidad.model.ChildPropertyTreeModel.setRowKey(ChildPropertyTreeModel.java:178)
at org.apache.myfaces.trinidad.component.UIXCollection.setRowKey(UIXCollection.java:425)
at oracle.apps.aia.sr.common.JSFUtils.getTreeSelectedNode(JSFUtils.java:392)
So, I thought that maybe this wasn't the best way to get the selected node. So, after some research I changed the logic to be:
public static JUCtrlHierNodeBinding getTreeSelectedNode(RichTree tree) {
JUCtrlHierNodeBinding node = null;
if (tree != null) {
CollectionModel treeModel = (CollectionModel)tree.getValue();
if (treeModel != null ){
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding)treeModel.getWrappedData();
if (treeBinding != null){
RowKeySet rks = tree.getSelectedRowKeys();
if (rks != null){
if (!rks.isEmpty()){
List firstSet = (List)rks.iterator().next();
node = treeBinding.findNodeByKeyPath(firstSet);
return node;
However, at the time of the beforePhase (I even tried an afterPhase listener) the tree isn't null, but the CollectionModel is null for some reason. I'm not sure where to go from here, any ideas?

Hi,
if you use lazy loading (contentdelivery="lazy" then the data is queried after the tree renders. ou would need to set it to immediate to acess data suring the Preparerender phase).
Frank

Similar Messages

  • How to get the selected node value of a tree which is build on java code

    Hi Experts,
    How can i get the selected node value if I build the tree programatically.
    I am using the following code in selectionListener but it is throwing error.
    RichTreeTable treeTable = (RichTreeTable)getQaReasontreeTable();
    CollectionModel _tableModel =
    (CollectionModel)treeTable.getValue();
    RowKeySet _selectedRowData = treeTable.getSelectedRowKeys();
    Iterator rksIterator = _selectedRowData.iterator();
    String selectedQaCode ="";
    while (rksIterator.hasNext()) {
    List key = (List)rksIterator.next();
    JUCtrlHierBinding treeTableBinding =
    (JUCtrlHierBinding)((CollectionModel)treeTable.getValue()).getWrappedData();
    JUCtrlHierNodeBinding nodeBinding =
    treeTableBinding.findNodeByKeyPath(key);
    String nodeStuctureDefname =
    nodeBinding.getHierTypeBinding().getStructureDefName();
    selectedQaCode = selectedQaCode + nodeBinding.getAttribute(0);
    where I am using following link to create a tree with java code.
    http://one-size-doesnt-fit-all.blogspot.com/2007/05/back-to-programming-programmatic-adf.html
    Please help me in resolving this issue.
    Regards
    Gayaz

    Hi,
    you should also move
    JUCtrlHierBinding treeTableBinding =
    (JUCtrlHierBinding)((CollectionModel)treeTable.getValue()).getWrappedData();
    out of the while loop as this is not necessary to be repeated for each key in the set
    Frank

  • How could i get the selected node in the JTree

    getLastSelectedPathComponent() �returns the parent node of currenr selected, so how could I get the selected node itself in the JTree
    I will appretiate for any help!

    i think you can get by....
    TreePath treePath = tree.getSelectionPath();
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();

  • Get current Tree Select Node

    Hi,ALL
    I want to return JTree selection.
    As you know If use JTree object, we can use
    getSelectionPaths(), and use Treepah object method
    getLastPathComponent to get selected node.
    What I want to do is.
    My JTree Object model is DefaultMutableTreeNode
    i want to use DefaultMutableTreeNode to access selected Node.
    Can I do like this?
    If I can, how to do it?
    Thanks in advanced

    Hi,
    if you following that pdf ,
    i think your not implemented the below code in DomodifyView method
    if (firstTime) {
          IWDTreeNodeType treeNode = (IWDTreeNodeType) view.getElement("TheNode");
          /* The following line is necessary to create parameter mapping from parameter "path" to parameter "selectedElement".
    Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
    that raised the onAction event. Parameter "selectedElement" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
    that handles the onAction. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
    be accessed within the event handler
          treeNode.mappingOfOnAction().addSourceMapping("path", "selectedElement");
          /* The following line is necessary to create parameter mapping from parameter "path" to parameter "element".
    Parameter "path" is of type string and contains the string representation of the tree element (its corresponding context element to be exact)
    that raised the onLoadChildren event. Parameter "element" is of type IWDNodeElement (or extends it) and is defined as parameter in the event handler
    that handles the onLoadChildren. The parameter mapping defined here translates the String "path" into the corresponding context element that then can
    be accessed within the event handler
          treeNode.mappingOfOnLoadChildren().addSourceMapping("path", "element");
    please cross check once.
    Thanks,
    Ramesh

  • Dynamic tree selected node property id issue...

    hi -
    I'm successfully building a two-tier tree dynamically, but when a node is selected, it isn't consistently giving the correct property id for that node... sometimes it's correct, sometimes it's null, sometimes I have to select the node twice to get a value, or it shows the value from the previous selected node...
    I've tried tree1.getSelected() and tree1.getCookieSelectedTreeNode() but it's still the same result... it acts as though the cookie isn't getting updated each time... I've tried it with and without setting 'immediate' with the same result... below is the relevant part of my code... does anyone see why it's not getting the selected property id each time? help and suggestions welcome... Thanks
    try {
    java.util.List newNodeChildren = newNode.getChildren();
    while (srs.next()){
    TreeNode newNode2 = new TreeNode();
    newNode2.setTarget("_blank");
    newNode2.setText(srs.getString( "issue_title"));
    newNode2.setId("x" + issue_id);
    //Setup action event
    Hyperlink nodelink = new Hyperlink();
    nodelink.setText(newNode2.getText());
    nodelink.setId(newNode2.getId());
    Class[] signatures = {ActionEvent.class};
    MethodBinding mb1 = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{Page2.treeNodeActionListener}", signatures);
    nodelink.setActionListener(mb1);
    newNode2.getFacets().put(newNode2.CONTENT_FACET_KEY, nodelink);
    newNodeChildren.add(newNode2);
    srs.release();
    } catch(SQLException ex) {
    / error("SQL Error StatusTree Retrieval: " + ex);
    public void treeNodeActionListener(ActionEvent event) {
    String id = tree1.getCookieSelectedTreeNode();
    String actualId = id.substring(id.lastIndexOf(":")+2);
    info("treeNodeActionListener actualId = " + actualId);
    }

    Hi,
    1 I dropped Tree component from Palette. I deleted TreeNode1.
    <ui:tree binding="#{Navigator.tree1}" expandOnSelect="false" id="tree1" immediate="true" style="left: 0px; top: 0px; position: absolute" text="Sometext"/>
    2 In the init() method I called paintTree()
    It works fine.
    I use action method because I need only the id of selected node but I tested also listener method and it works
    Here is my code
    public void paintTree(){
    ArrayList conturi=new ArrayList();
    TreeNode nodN1 = new TreeNode();
    TreeNode nodN2 = new TreeNode();
    TreeNode nodN3 = new TreeNode();
    TreeNode nodN9 = new TreeNode();
    String Id;
    int lga=0;
    int lgc=0;
    try {
    conturi=getSessionBean1().getSes01FacadeRemoteClient1().getMyEjbMethod();
    } catch (Exception ex) {
    log(".....", ex);
    Iterator iterator=conturi.iterator();
    while (iterator.hasNext()) {
    detalii.Conturi cont=(detalii.Conturi)iterator.next();
    lgc=cont.getConts().length();
    if (lga < lgc) {
    if (lgc == 1) {
    nodN1=new TreeNode();
    Id= "Node_"+cont.getId();
    nodN1.setId(Id);
    nodN1.setText(cont.getDenumire());
    tree1.getChildren().add(nodN1);
    if (lgc == 2){
    nodN2=new TreeNode();
    Id= "Node_"+cont.getId();
    nodN2.setId(Id);
    nodN2.setText(cont.getConts()+"-"+cont.getDenumire());
    nodN2.setStyleClass("leftAligned");
    nodN1.getChildren().add(nodN2);
    if (lgc == 3){
    nodN3=new TreeNode();
    Id= "Node_"+cont.getId();
    nodN3.setId(Id);
    nodN3.setText(cont.getConts());
    nodN3.setStyleClass("leftAligned");
    FacesContext context=FacesContext.getCurrentInstance();
    MethodBinding mb1 = context.getApplication().createMethodBinding("#{Navigator.treeNode_action}", null);
    nodN3.setAction(mb1);
    nodN2.getChildren().add(nodN3);
    } //end-if
    } //end while
    public String treeNode_action() {
    try {
    clientId=tree1.getCookieSelectedTreeNode();
    String id =clientId.substring(clientId.lastIndexOf("_")+1);
    getSessionBean1().setContId(id);
    info("clientId = "+ clientId);
    } catch (Exception ex) {
    log("Error Description", ex);
    return null;
    }

  • How to get UIComponent of the selected node in af:tree with drag and drop

    Hi
    Are there examples showing how one could get a UIComponent using DropEvent to be used with a Popup showing as a custom "context menu" at the target node ?
    Right now, with dropEvent.getDropComponent, we could only get the tree.
    We like to get its selected node so that the popup shows at the node level, not at the tree level.
    Thanks

    Hi Frank
    Thanks for responding.
    We like to show on our custom "context menu" using PopupHints (not using facet name contextmenu) with 3 commandMenuItems.
    Since component id is needed by PopupHints to place this custom "context menu", we tried
    RichTree dropTree = (RichTree)dropEvent.getDropComponent();
    alignId = dropTree.getClientId(context);
    // alignId = pt1:pt_region1:1:pt1:pc1:navTree
    getClientId returns us the tree id and hence the context menu is placed next to tree.
    We like to place the context menu next to a target node of the tree when dragging and dropping.
    But we couldn't figure out how to get that node id.
    In your suggestion,
    List dropRowKey = (List) dropEvent.getDropSite();
    RichTree dropComponent = (RichTree) dropEvent.getDropComponent();
    dropCompoent.setRowKey(dropRowKey);
    how do we then get the id of this node then ? What's the method ?
    Thanks Frank

  • Get selected node of an adf tree in backing class

    hi,
    i am deploying an adf web application, i use jdeveloper 11g and a weblogic webserver.
    i have a bean family this bean contains a list of families and a parrentfamily object, so it is a rekursive relationship.
    i use the adf tree component to show all the families starting with the root family. works fine. only had to create a data controle of the bean and with dragndrop i create the adf tree.
    now i want to create a subfamily of any family shown in the tree, so i need the selected tree node in my backing bean (in a methode which is the action of my buttono) of the adf page.
    but iam unable to get the data.
    so my question i searched many times for:
    What is the best and easiest way to get the selection of an adf tree in the backing bean of the page?

    Hi,
    here's how you get the object itself, assuming your model is POJO based. Assuming "tree" is a variable pointing to a RichTree instance
    CollectionModel treeModel = (CollectionModel) tree.getValue();
    JUCtrlHierBinding treeBinding = (JUCtrlHierBinding) treeModel.getWrappedData();
    RowKeySet rks = tree.getSelectedRowKeys();
    if(!rks.isEmpty()){
      List firstSet = (List)rks.iterator().next();
    JUCtrlHierNodeBinding node = treeBinding.findNodeByKeyPath(firstSet);
      DCDataRow rw = (DCDataRow) node.getRow();
      //get the object
    Object entity = rw.getDataProvider();       
    }                         Frank

  • How to get Text for nodes in Tree Structure

    Hi Friends,
    How to get Text for nodes in Tree Structure
    REPORT  YFIIN_REP_TREE_STRUCTURE  no standard page heading.
                       I N I T I A L I Z A T I O N
    INITIALIZATION.
    AUTHORITY-CHECK OBJECT 'ZPRCHK_NEW' :
                      ID 'YFIINICD' FIELD SY-TCODE.
      IF SY-SUBRC NE 0.
        MESSAGE I000(yFI02) with SY-TCODE .
        LEAVE PROGRAM.
      ENDIF.
    class screen_init definition create private.
    Public section
      public section.
        class-methods init_screen.
        methods constructor.
    Private section
      private section.
        data: container1 type ref to cl_gui_custom_container,
              container2 type ref to cl_gui_custom_container,
              tree type ref to cl_gui_simple_tree.
        methods: fill_tree.
    endclass.
    Class for Handling Events
    class screen_handler definition.
    Public section
      public section.
        methods: constructor importing container
                   type ref to cl_gui_custom_container,
                 handle_node_double_click
                   for event node_double_click
                   of cl_gui_simple_tree
                   importing node_key .
    Private section
      private section.
    endclass.
    *&                        Classes implementation
    class screen_init implementation.
    *&                        Method INIT_SCREEN
      method init_screen.
        data screen type ref to screen_init.
        create object screen.
      endmethod.
    *&                        Method CONSTRUCTOR
      method constructor.
        data: events type cntl_simple_events,
              event like line of events,
              event_handler type ref to screen_handler.
        create object: container1 exporting container_name = 'CUSTOM_1',
                       tree exporting parent = container1
                         node_selection_mode =
                cl_gui_simple_tree=>node_sel_mode_multiple.
        create object: container2 exporting container_name = 'CUSTOM_2',
        event_handler exporting container = container2.
    event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
        event-appl_event = ' '.   "system event, does not trigger PAI
        append event to events.
        call method tree->set_registered_events
             exporting events = events.
        set handler event_handler->handle_node_double_click for tree.
         call method: me->fill_tree.
      endmethod.
    *&                        Method FILL_TREE
      method fill_tree.
        data: node_table type table of abdemonode,
              node type abdemonode.
    types:    begin of tree_node,
              folder(50) type c,
              tcode(60) type c,
              tcode1(60) type c,
              tcode2(60) type c,
              text(60) type c,
              text1(60) type c,
              text2(60) type c,
              end of tree_node.
      data:  wa_tree_node type tree_node,
                t_tree_node type table of tree_node.
    wa_tree_node-folder = text-001.
    wa_tree_node-tcode  = text-002.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-003.
    wa_tree_node-text1 =  'GR/IR aging'.
    wa_tree_node-tcode2 = text-004.
    wa_tree_node-text2 =  'Bank Balance'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    wa_tree_node-folder = text-005.
    wa_tree_node-tcode  = text-006.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-007.
    wa_tree_node-text1 =  'Creditors ageing'.
    wa_tree_node-tcode2 = text-008.
    wa_tree_node-text2 =  'Creditors ageing'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    wa_tree_node-folder = text-009.
    wa_tree_node-tcode  = text-010.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-011.
    wa_tree_node-text1 =  'Creditors ageing'.
    wa_tree_node-tcode2 = text-012.
    wa_tree_node-text2 =  'Creditors ageing'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    node-hidden = ' '.                 " All nodes are visible,
        node-disabled = ' '.               " selectable,
        node-isfolder = 'X'.                                    " a folder,
        node-expander = ' '.               " have no '+' sign forexpansion.
        loop at t_tree_node into wa_tree_node.
          at new folder.
            node-isfolder = 'X'.                      " a folder,
            node-node_key = wa_tree_node-folder.
                   clear node-relatkey.
            clear node-relatship.
            node-text = wa_tree_node-folder.
            node-n_image =   ' '.
            node-exp_image = ' '.
            append node to node_table.
          endat.
         at new tcode .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode.
             node-text = wa_tree_node-text .
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
          endat.
          append node to node_table.
        at new tcode1 .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode1.
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
              node-text = wa_tree_node-text1.
         endat.
          append node to node_table.
           at new tcode2 .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode2.
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
            node-text = wa_tree_node-text2.
         endat.
          append node to node_table.
        endloop.
        call method tree->add_nodes
             exporting table_structure_name = 'ABDEMONODE'
                       node_table = node_table.
      endmethod.
    endclass.
    *&                        Class implementation
    class screen_handler implementation.
    *&                        Method CONSTRUCTOR
      method constructor.
       create object: HTML_VIEWER exporting PARENT = CONTAINER,
                      LIST_VIEWER exporting I_PARENT = CONTAINER.
      endmethod.
    *&                 Method HANDLE_NODE_DOUBLE_CLICK
      method handle_node_double_click.
      case node_key(12).
    when 'Creditors'.
    submit YFIIN_REP_CREADITORS_AGING  via selection-screen and return.
    when  'Vendor'.
    submit YFIIN_REP_VENDOR_OUTSTANDING  via selection-screen and return.
    when 'Customer'.
    submit YFIIN_REP_CUSTOMER_OUTSTANDING  via selection-screen and
    return.
    when 'GR/IR'.
    submit YFIIN_REP_GRIR_AGING  via selection-screen and return.
    when 'Acc_Doc_List'.
    submit YFIIN_REP_ACCOUNTINGDOCLIST  via selection-screen and return.
    when 'Bank Bal'.
    submit YFIIN_REP_BANKBALANCE  via selection-screen and return.
    when 'Ven_Cus_Dtl'.
    submit YFIIN_REP_VENDORCUST_DETAIL via selection-screen and return.
    when 'G/L_Open_Bal'.
    submit YFIIN_REP_OPENINGBALANCE via selection-screen and return.
    when 'Usr_Authn'.
    submit YFIIN_REP_USERAUTHRIZATION via selection-screen and return.
    endcase.
      endmethod.
    endclass.
    Program execution ************************************************
    load-of-program.
      call screen 9001.
    at selection-screen.
    Dialog Modules PBO
    *&      Module  STATUS_9001  OUTPUT
          text
    module status_9001 output.
      set pf-status 'SCREEN_9001'.
      set titlebar 'TIT_9001'.
      call method screen_init=>init_screen.
    endmodule.                 " STATUS_9001  OUTPUT
    Dialog Modules PAI
    *&      Module  USER_COMMAND_9001  INPUT
          text
    module user_command_9001 input.
    endmodule.                 " USER_COMMAND_9001  INPUT
    *&      Module  exit_9001  INPUT
          text
    module exit_9001 input.
    case sy-ucomm.
    when 'EXIT'.
      set screen 0.
    endcase.
    endmodule.
            exit_9001  INPUT

    you can read  the table node_table with nody key value which imports when docubble click the the tree node (Double clifk event).
    Regards,
    Gopi .
    Reward points if helpfull.

  • JTree: How to get the currently selected node

    How do I get the currently selected node in JTree?
    getLastSelectedPathComponent() this method always return the last selected node and not the current one.
    Thanks in advance
    Sachin

    Use
    TreePath selectedPath = tree.getSelectionPath()If your tree allows multiple selections, use
    TreePath [] selectedPaths = tree.getSelectionPaths() this will return an array of all selected tree paths.
    Once you get the tree path, call the treePath.getLastPathComponent(). this should tell you the currently selected node.
    Hope this helps
    Sai Pullabhotla

  • Right click select node in tree (for a standalone Air app)?

    For the sake of userfriendliness (in regard to a context menu) I wold like to "move" the selected node in a tree to the node that currently has the focus when right clicking it - like how the context menu access in windows file explorer works (focus and selected item are always the same  when right clicking).
    In worst case scenario I would like to disable a created context menu if the selected node and the node that currently has the focus are not the same).
    Now users can get confused when right clicking to access my context menu, in the tree structure, if the selected node and the node they are currently hovering over (and thus are in focus) are different.
    I was thinking of finding which node currently has the focus and then making that node the selected node - but I cant get it to work:-).
    Please, help a beginner.

    Hi,
    Duplicate thread of
    http://swforum.sun.com/jive/thread.jspa?threadID=64518
    MJ

  • Help in getting current expanded node in Tree UI

    HI,
    I have a requirement to build a tree dynamically. On expanding each node I need to create sub nodes inside that. But it is always creating inside the node where the lead selection is and not inside the current expanded node. Even though I have used getTreeSelection () to get the current element.
    <b>Detailed description about the application.,</b>
    I have created a context with the following structure,
    TreeNode (0..n)
    |
    |--> ChildNode (recursive SiteTree)
    |--> Name (string)
    I have created a Tree UI Element in the view and inserted a node type 'TreeNodeType'.
    I have set the properties of the inserted node type as given bellow,
    Value Attribute in TreeNode -> Name I have assigned to 'Text' property of 'TreeNodeType'.
    Initially I have created four nodes in the init() method ., using the following code :
    for(int i=0;i<3;i++)
    IPrivateTestTreeView.ITreeNodeNode treenode=wdContext.nodeTreeNode();
    IPrivateTestTreeView.ITreeNodeElement treeelement=wdContext.createTreeNodeElement();
    treeelement.setName("Testroot:"+i);
    treenode.addElement(treeelement);
    Now I need to create sub-nodes for this dynamically.,
    I have created an action and called it in 'onLoadChildren' event of 'TreeNodeType' with the following code:
    public void OnCurrentSelection()
    IPrivateTestTreeView.ITreeNodeElement el = wdContext.nodeTreeNode().getTreeSelection();
    wdComponentAPI.getMessageManager().reportSuccess(el.getName());
    <b>
    Where this returns me only the name of LeadSelection node and not the  node which i try to expand.  </b>
    Is there anyway I can get the currently expanded node., Kindly help me out in this.
    Points will be rewarded for helpful answers. Thanks in advance.
    Regards,
    Nirmal

    HI Ayyapparaj ,
    <b>First I would like to thank you for your reply.</b>
    So it means that we cannot identify the currently expanded node in tree UI element and It will always be the lead selection node we will be able to get rite?
    Can we make the current lead selection to currently expanded node 'By Default'?
    Coming back to your solution.,
    I created a context element 'isExpanded' of type boolean inside the TreeNode.
    You said that there will be a call made to 'getter and setter' methods while we expand the node and we can set the lead selection to that element from there.
    Could you please give me some more details of how to achieve it.
    Thanks in advance.
    Regards,
    Nirmal G

  • Can't get Checkbox selection status in Tree

    Hi,
    I'm using a Checkbox Tree which I got from here: [http://www.java2s.com/Code/Java/Swing-JFC/CheckBoxNodeTreeSample.htm|http://www.java2s.com/Code/Java/Swing-JFC/CheckBoxNodeTreeSample.htm]
    Now, I want to determine whether the Checkboxes are selected or not.
    Unfortunately, the custom CheckBox model class always returns true, which is stored in a Vector.
    In short, this is how the checkTree is created:
    CheckBoxNode tabFormatNode = new CheckBoxNode[]{new CheckBoxNode("GP3", true),
                                        new CheckBoxNode("GP4", true),
                                        new CheckBoxNode("GP5", true)};
    NamedVector formatVector = new NamedVector("Format", tabFormatNode);
    Object[] rootNodes = new Object[]{ formatVector }
    Vector rootVector = new NamedVector("root", rootNodes);
    TreeModel model = createTreeModel(rootVector);
    setModel(model);As I said, when I retrieve a CheckBoxNode from the Vector, it always return true on isSelected(), so that's no use.
    However, the renderer does manage to get the selection status correctly.
    private static class CheckBoxNodeRenderer implements TreeCellRenderer
            private JCheckBox leafRenderer = new JCheckBox();
            protected JCheckBox getLeafRenderer()
                return leafRenderer;
            public CheckBoxNodeRenderer()
            public Component getTreeCellRendererComponent(JTree tree, Object value,
                  boolean selected, boolean expanded, boolean leaf, int row,
                  boolean hasFocus)
                Component returnValue;
                if (leaf)
                    String stringValue = tree.convertValueToText(value, selected,
                        expanded, leaf, row, false);
                    leafRenderer.setText(stringValue);
                    leafRenderer.setSelected(false);
                    if (selected)
                        leafRenderer.setForeground(selectionForeground);
                        leafRenderer.setBackground(selectionBackground);
                    else
                        leafRenderer.setForeground(textForeground);
                        leafRenderer.setBackground(textBackground);
                    if ((value != null) && (value instanceof DefaultMutableTreeNode))
                        Object userObject = ((DefaultMutableTreeNode) value)
                        .getUserObject();
                        if (userObject instanceof CheckBoxNode)
                            CheckBoxNode node = (CheckBoxNode) userObject;
                            leafRenderer.setText(node.getText());
                            leafRenderer.setSelected(node.isSelected());
                            // eigen
                            leafRenderer.setEnabled(Overview.getTabbedPane().getActiveTabList().isLeftPaneEnabled());
                    returnValue = leafRenderer;
                else
                  returnValue = nonLeafRenderer.getTreeCellRendererComponent(tree,
                      value, selected, expanded, leaf, row, hasFocus);
                return returnValue;
        }Could anyone help me with retrieving the correct selection values of the CheckBoxes?
    Edited by: Tails on 21-mrt-2008 13:07

    OK Tails. here are the changes you need, in CheckBoxNodeEditor method getTreeCellEditorComponent. Note that Component editor is now declared as final so that in can be accessed from within the inner class.   public Component getTreeCellEditorComponent (JTree tree, Object value,
             boolean selected, boolean expanded, boolean leaf, int row) {
          // change to final
          final Component editor = renderer.getTreeCellRendererComponent (tree, value,
                true, expanded, leaf, row, true);
          // editor always selected / focused
          // line added
          final CheckBoxNode cbn = (CheckBoxNode) ((DefaultMutableTreeNode) value).getUserObject ();
          ItemListener itemListener = new ItemListener () {
             public void itemStateChanged (ItemEvent itemEvent) {
                // line added
                cbn.setSelected (((CheckBoxNode) getCellEditorValue ()).isSelected ());
                if (stopCellEditing ()) {
                   fireEditingStopped ();
          if (editor instanceof JCheckBox) {
             ((JCheckBox) editor).addItemListener (itemListener);
          return editor;
       }Get back to us on whether that solves the problem, willya.
    db

  • JTree get selected node/object values

    I wan to get all the selected nodes/objects values that I added to the JTree. How can I do this?
    Thanks.

    TreePath[] paths = tree.getSelectedPath();
    for(int i = 0; i < paths.length; i++){
    TreeNode node = (TreeNode)paths.getLastPathComponent();
    Object mySelectedObject = node.getUserObject();
    }Some minor Errors
    We have to use array paths[i] instead of paths
    The correct code as used by me is
            javax.swing.tree.TreePath[] paths = jTree1.getSelectionModel().getSelectionPaths();
            for(int i = 0; i < paths.length; i++){
                javax.swing.tree.TreeNode node = (javax.swing.tree.TreeNode)paths.getLastPathComponent();
    System.out.println(((javax.swing.tree.DefaultMutableTreeNode)node).getUserObject());
    CSJakharia

  • Selecting node of tree

    Hello thanks for anyone before..
    I have a problem with selection of my Tree. my tree nodes contains of ItemFormat like :
    class ItemFormat
    private String code;
    private String description;
    ..... mutator and accessor methods......
    when i have displayed my tree successfully i can print on screen about selected itemFormat to display description instance variable.
    but after I edit my node and then i selected again the selected node can't be casted to ItemFormat to display its description...
    please help me...
    thanks before....

    Thanks Tony,
    The application I have is a means of commercial seafood dealers recording what species they have purchased/landed. The page is designed with a tree listing all of the species and their sizes and then the tabular report of landings. The current application uses a collection to display the landings....I was trying to get rid of the collection and populate the table directly.
    thanks for getting back to me. Sounds like I will need to keep the collection....just looking for examples.

  • ADF Tree 10.1.3.1, not highlighting the selected node.

    Hi,
    I'm having a problem highlighting the selected node in the ADF CoreTree.
    I use the treehandler and model as described in the link: 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
    I use this objects because my tree was showing leaf node with the image to collapse.
    The tree now looks great, the only problem is that when i click on a node the focusRowKey is set accordingly(debugging the getter and setter) but is not show as the selected node.
    The tree jspx code looks the follow:
                   <!--TREE-->
                                     <af:tree value="#{ActosTreeHandler.treemodel}" var="node"
                                               focusRowKey="#{ActosTreeHandler.focusRowKey}"
                                               id="treeActos"
                                               varStatus="nodeStatus" binding="#{ActosTreeHandler.jsfTree}">
                                        <f:facet name="nodeStamp">
                                          <af:commandLink text="#{node.description}" partialTriggers="treeActos"
                                                          action="#{backing_documentos_detalhesDocumento.treeAction}">
                                            <!--disabled="#{node.nodeType != 'ACTO'}"-->
                                            <af:setActionListener from="#{ActosTreeHandler.jsfTree.rowKey}"
                                                                  to="#{ActosTreeHandler.focusRowKey}"/>
                                            <af:setActionListener from="#{node}"
                                                                  to="#{ActosTreeHandler.selectedNode}"/>
                                            <af:resetActionListener/>
                                          </af:commandLink>
                                        </f:facet>
                                      </af:tree>Does anyone know how this can be solved?
    Best Regards.

    Hi,
    is this the same as
    Re: Facing a problem in programmatically setting focus on a node in <af:tre
    Frank

Maybe you are looking for

  • Fork and BPM

    Hi I am using Fork in the BPM to collect and merge 3 messages. This is same as STD pattern "BpmPatternCollectMultiIf". It is working fine, it collects--> transforms --> sends. But always two PE are in "In process" state with a "clock" indicator. I tr

  • Java Script doesn't work on Firefox 8?

    I have noticed that (some) Java Script does not work on Firefox 8.0. Is there a correction for this?

  • SDI interface for Mac to connect to SE-800DV

    I have three MacBook Pros (all with HDMI out) and a MacPro desktop (two HDMIs). I also own a DataVideo SE-800DV video switcher which allows you to connect a PC to it to overlay graphics for titling, animation, etc. Does anyone have any experience put

  • Mac 10.8.2 panic report

    Since updating to 10.8.2, my computer restarts up to 4 times a day, and I receive panic reports. Here is my latest report. Thank you very much with helping me out with this nuisance. Interval Since Last Panic Report:  155666 sec Panics Since Last Rep

  • CS4 liquify tool error

    Something very strange has just started to happen to me with CS4.  I've been running CS4 on my Mac Pro for quite some time without any problems.  Just yesterday I began to run into something like a mini "crash" when using the liquify tools. Previousl