Af:tree selected item

I want to display the selected item from a tree (and to store this into a variable). I tried with selection_listener, but I don't know exactly what to write in the bean. The disclosed_row_keys is used to expand all nodes.
<af:tree value="#{bindings.ConfigTreeParent2.treeModel}"
var="node"
rowSelection="single" id="tree1"
selectionListener="#{left_tree.selection_listener}"
disclosedRowKeys="#{left_tree.disclosed_row_keys}">
<f:facet name="nodeStamp">
<af:outputText value="#{node}"/>
</f:facet>
</af:tree>
Thanks,
vio

Hi vio,
The method signature for selectionListener is
public void someMethodName(SelectionEvent ev);
The selection event contains the selected row keys (well actually it contains the delta which should be improved imho like oldSelection and newSelection, but in the case of single selection, you can simply use the added list more or less), you can then extract the data associated with each row keys. So, in your case, I suggest you inject the TreeModel in your bean. Here's an example:
In the code:
public class MyTreeController
    private TreeModel model;
    private MySelectionManager selectionManager;
    public TreeModel getTreeModel()
        return model;
    public void setTreeModel(TreeModel model)
        this.model = model;
    public MySelectionManager getSelectionManager()
        return selectionManager;
    public void setSelectionManager(MySelectionManager manager)
        this.selectionManager = manager;
    public void selectionPerformed(SelectionEvent ev)
        Object selected = getFirstRowKey(ev.getAddedSet());
        if (selected == null)
            Object unselected = getFirstRowKey(ev.getRemovedSet());
            if (selectionManager.isSelected(getRowData(unselected)))
                selectionManager.setSelection(null);
        else
            selectionManager.setSelection(getRowData(selected));
    private Object getFirstRowKey(RowKeySet set)
        for (Object key : set)
            return key;
        return null;
    private Object getRowData(Object rowKey)
        TreeModel model = getTreeModel();
        Object oldRowKey = model.getRowKey();
        try
            model.setRowKey(rowKey);
            return model.getRowData();
        finally
            model.setRowKey(oldRowKey); // Always restore the state
public class MySelectionManager
    private Object selection; // Or another more precise type
    public Object getSelection()
        return selection;
    public boolean isSelected(Object data)
        return selection != null && selection.equals(data);
    public void setSelection(Object selection)
        this.selection = selection;
}In the faces-config.xml
<managed-bean>
  <managed-bean-name>selectionManager</managed-bean-name>
  <managed-bean-class>MySelectionManager</managed-bean-class>
  <managed-bean-scope>pageFlow</managed-bean-scope> <!-- That one can be persistent across requests -->
</managed-bean>
<managed-bean>
  <managed-bean-name>treeController</managed-bean-name>
  <managed-bean-class>MyTreeController</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
<!-- request scope is important here since we don't know the exact lifespan of bindings.ConfigTreeParent2.treeModel -->
  <managed-property>
    <property-name>selectionManager</property-name>
    <property-class>MySelectionManager</property-class>
    <value>#{selectionManager}</value>
  </managed-property>
  <managed-property>
    <property-name>treeModel</property-name>
    <property-class>org.apache.myfaces.trinidad.model.TreeModel</property-class>
    <value>#{bindings.ConfigTreeParent2.treeModel}</value>
  </managed-property>
</managed-bean>In your page:
<af:tree value="#{treeController.treeModel}"
         var="node"
         id="tree1"
         rowSelection="single"
         selectionListener="#{treeController.selectionPerformed}"
         disclosedRowKeys="#{left_tree.disclosed_row_keys}">
  <f:facet name="nodeStamp">
    <af:outputText value="#{node}"/>
  </f:facet>
</af:tree>Note that I preferred to use the tree model from the bean rather than using directly the databindings here. I did so to improve reusability and declarativity of the page as you could now simply alter the injected tree model within the faces-config to have your page point on a completely different data source.
Regards,
~ Simon

Similar Messages

  • How to get selected items from a tree in backing bean without adfbc

    Hi ADF Experts,
    Below is my code for af:tree. My question is how can I get selected Items from the selectionListener (without adf bc) this uses formation of tree from backing bean.
    Using Jdev 11.1.1.7.0
    <af:tree var="node" value="#{pageFlowScope.MerchandizeBean.model}"
                      binding="#{pageFlowScope.MerchandizeBean.treeModel}"     id="tree" immediate="true" autoHeightRows="0"
                           styleClass="AFStretchWidth" rowSelection="multiple"
                           selectionListener="#{pageFlowScope.MerchandizeBean.treeNodeSelection}">
                    <f:facet name="nodeStamp">
                      <af:commandLink text="#{node.classDescription}"
                           actionListener="#{pageFlowScope.MerchandizeBean.createListManyItemForMerchandise}"           id="displayTable" partialSubmit="true">
                      </af:commandLink>
                    </f:facet>
                  </af:tree>
        public void treeNodeSelection(SelectionEvent selectionEvent) {
            // Add event code here...
            RichTree tree = (RichTree)selectionEvent.getSource();
                    TreeModel model = (TreeModel)tree.getValue();
                    //get selected value
    Thanks
    Roy

    Hi,
    in a multi select case, try
    RowKeySet rks = tree.getSelectedRowKeys();
    Iterator iter = rks.iterator();
    while(iterator.hasNext()){
    Object aKey = iterator.next();
    tree. setRowKey(aKey);
    Object rowData ? tree.getRowData();
      .... do something with the data here ...
    Frank

  • ADF Tree with Boolean Check Box: How to find selected items

    Hi Experts,
    ADF: 11.1.1.5.0
    WLS: 10.3.6
    I am using an ADF Tree which contains elements at two levels (say Departments and Employees). My requirement is to give provision for user to select Departments and Employees using the check boxes. User should be able to select what ever Departments he/she likes and what ever employees he/she likes. There should not be a provision to select Employee with out selecting the corresponding Department (root node in the tree).
    I am facing the below issues while trying to implement this use case:
    1. Always, only the first master record will be expanded by default (I am using "Display Row" property value as "default" and "ExpandAllEnabled" as "true"). My need is to expand all the master records by default. So that user need not explicitly expand each master record node and then select the associated child records.
    2. Currently, I am using value change listener associated to af:selectBooleanCheckBox to identify the Departments and Employee records that have been selected. Since not all departments (masters) are expanded by default, if user selects the check box of department (master) and then expands the department node, automatically all the employees of that department are selected. But, this event is not triggering the value change listener for the employee records. Because of this, after a department node is selected and then expanded, all the child elements' check boxes are selected but the events are not generated. Hence, I am not able to capture the selection of employee records.
    To summarize,
    1. Please let me know how to expand all master nodes in af:Tree by default.
    2. Please let me know the best approach to identify the selected items (both master and detail items) in the af:Tree component using af:selectBooleanCheckBox.
    Thanks in advance,
    Rathnam

    Hi,
                Can you please elaborate the solution? I have a similar problem in
    https://forums.oracle.com/thread/2579664

  • P6 Professional R8.3 - (Cannot move selected items because the result will exceed the limit of WBS tree maximum levels)

    Hi,
    Has anyone encountered this error "Cannot move selected items because the result will exceed the limit of WBS tree maximum levels"?
    Please advise if there's any way around / solution to this. http://s8.postimg.org/bj900spcl/1_error.jpg
    Thanks.

    Thank you so much MichaelRidino!

  • State Change causing tree item to loss selected item highlight

    I'm looking for some guidance on a situation i'm encountering. I've an application with a tree component which will be used as a report selector in all view states. The parent nodes are not selectable but the children are. Each child has a for a lack of a better term parameter classification. When a report item is selected in the tree then a state change occurs and displays the appropriate parameter selection view.
    My issue is this. Upon clicking an item and displaying the new state for the first time, the selected item in the tree losses the visual representation or highlight around the selected item. But within the debugger it still shows which item is the selectedItem.  Once the state has been displayed at least once...i.e. I select other items and then eventually back to initial tree item when the state changes it does not loss the highlight on the selected tree item.
    Couple things I've tried to see if i'm in the right neck of the woods is use the currentStateChange and currentStateChanging handlers to do a bit of tracing and found that the tree item remains selected all the way through both currentStateChanging and then even in the currentStateChange...the redraw occurs just after which is when the tree item losses its highlight.
    Does anyone have any ideas or even encounter this?

    Good question. Well you're right in asking. Just using a spark Label to show me the label of the selectedItem, upon the first time I click on the selection nothing populates the label's text BUT the state changes as its suppose to. Took me clicking on it a second time to get the item to be highlighted and the label to show me what had been selected.
    My question here is...is there another event which is occurring after the changeState?

  • Tree Control Highlighti​ng Programmat​ically Selected Item

    Does anyone know whether it is possible to highlight a programmatically selected item in the LV Tree Control, eg I have used the "Get Child" method to select an item - how do I then highlight this item on the tree?

    Yes, you can write the value to a local variable for the tree control. This will have the effect of selecting the item--which will highlight just ike the user clicked on it.
    By the way, "Get Child" doesn't select an item in any sort of useful sense--it just tells you what the child is. Actually, it tells you what the first child under the indicated Parent is.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • LabVIEW 7 Tree Control - Selected Item

    Hi,
    Has anyone tried the new Tree control in LV7 yet? I can't seem to find a method to programatically determine what item in the tree has been selected by the user other than if the user has double clicked on the tree - can someone point me to the method? From a user interface perspective double clicking an item in a tree shouldn't be the only way to select an item and as a side effect double clicking on the LV7 tree item closes a branch if there are children under the node double clicked on, which is very undesirable when only selecting an item.
    Cheers,
    Wayne

    WPS,
    The tree control's data, which is available from its terminal, is the tag(s) of the selected item(s).
    -Jim

  • Previous Values of Selected Items in a Datagrid

    I have a datagrid which the dataprovider is bound to an ArrayCollection of Value Objects from a web service.
    One other thing which is important to point out.   The Value Objects are created automatically for the Data/Service and so if I change the files, they will just be overwritten the next time I make a change to the service.
    The grid displays Inventory Items.    Lets say that Item 1 has a qty of 20.   Item 5 has a Qty of 10.
    The list in this grid is based upon the selection of a Location tree.   So it lists the inventory items for a certain location.
    I also have a second tree and grid for the to location inventory items.
    Between the two grids, there is a button which when clicked it iterates thru the selected items and creates a new item in the to list with qty 1 and saves it.  then decreases the current qty in the from list by one.
    So lets say I selected items 1 and 5 and then clicked the button.   A new copy of Items 1 and 5 are created in the to list with a qty of 1 and then saved.   Then the qty in the from list is decreased by 1 and saved and so the vales for 1 is now 19 and for 5 is 9.
    I would like to be able to change the qty in the from list to the qty I want to move.   So when the button is clicked the new item in the to list reflects the new qty and is saved.   Then the previous value of the current qty is decreased by the qty which is displayed in the grid
    So lets say I changed item 1 to 2 and Item 5 to 3 and then selected items 1 and 5 and then clicked the button.   A new copy of Items 1 and 5 are created in the to list with a qty of 2 for item 1 and 3 for item 5 and then saved.   Then the qty in the from list is decreased for Item 1 by 2 and item 5 by 3 and so now Item 1s qty is now 18 and items 5 qty is now 7.
    My first thought was if I had the previous values stored then no big deal.  But I put a break point at the point where the SelectedItems list is being iterated through and the previous values are not stored anywhere. 
    Any suggestions for this?

    ...in the mean time, this should be enough
    win.pnl.list1.onChange = function() {
         alert(this.selection.index); // for this to work set, multiselect:false
    I guess you already tried and the result is "undefined", the reason is you have this property
    multiselect:true
    in that case, selection returns an array,
    this.selection[0].index;
    would give you the first selected item, even if you only have one item selected, to get all selected items loop thru all items in the selection array.
    not sure if Peter's wonderful guide explains this (it is explained in the Tools Guide), but you should read it too, it has tons of great info.

  • How to check the selected items of a selectManyListbox in doDML of an EO ?

    Hello,
    I have a VO based on en EO. During the doDML(UPDATE) of that EO, I would like to check what items of a af:selectManyListbox have been selected.
    How could I get the checked items in the selectManyListbox (which belongs to the ViewController) in the doDML method of an EO (which belongs to the Model)?
    Many thanks

    Hello John,
    I know I cannot access the component directly. This is why I asked my question.
    The real case is rather complex and long to be copied and pasted here.
    Let me simplify it without being too generic.
    The VO is based on a hierarchical SQL query. All its EO attributes are transient. This VO is shown as a Tree in the page.
    Each node of the Tree has a checkBox. During commit (doDML() of the EO to be precise), for each checked node I need to access the selected items of a selectManyListbox in some proper way to perform further operations on the DB (no matter what now). The selectManyListbox is based on a second VO. As you may understand, the problem is that from the EO I don't have a direct access to the selectManyListbox. Also, as far as I know, the VO the selectManuListBox is based on does not have any informations about the selected elements, since the checkBox in the list cannot be associated to the VO. Basically I cannot know what elements have been choosen.
    I hope the problem is clear.

  • Preventing user from selecting item in JTree

    Does anyone know how to prevent the user from being able to change the cell in the tree that is currently selected?
    I have a JTree that the user can select items from but I want them to be able to click on a button and no longer be able to select an item in the tree until another button is pressed.
    Any ideas?

    hi
    i hope the code below helps ur purpose
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    public class Frame1 extends JFrame {
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    MyTree jTree1 = new MyTree();
    boolean blnSelection = true;
    /**Construct the frame*/
    public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    /**Component initialization*/
    private void jbInit() throws Exception {
    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(466, 319));
    this.setTitle("Frame Title");
    jButton1.setText("jButton1");
    jButton1.setBounds(new Rectangle(83, 254, 79, 27));
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton1_actionPerformed(e);
    jPanel1.setLayout(null);
    jButton2.setText("jButton2");
    jButton2.setBounds(new Rectangle(177, 256, 89, 23));
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton2_actionPerformed(e);
    jTree1.setBounds(new Rectangle(93, 30, 252, 195));
    contentPane.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jButton1, null);
    jPanel1.add(jButton2, null);
    jPanel1.add(jTree1, null);
    /**Overridden so we can exit when window is closed*/
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    void jButton1_actionPerformed(ActionEvent e) {
    blnSelection = false;
         jTree1.setSelectionPath(null);
    void jButton2_actionPerformed(ActionEvent e) {
    blnSelection = true;
    class MyTree extends JTree implements TreeSelectionListener
         public MyTree()
              super();
              init();
         private void init()
    this.getSelectionModel().setSelectionModeTreeSelectionModel.SINGLE_TREE_SELECTION);
              this.addTreeSelectionListener(this);
              this.setEditable(false);
         DefaultMutableTreeNode selectedNode = null;
         public void valueChanged(TreeSelectionEvent evt)
    if(!blnSelection)
         this.setSelectionPath(null);
         else
         TreePath tpSelectedTreePath = evt.getNewLeadSelectionPath();
         this.setSelectionPath(tpSelectedTreePath);
    cheers

  • Removal of Group Tree selection results in Highlighting

    Hello all,
    I'm using CR for VS2010 SP1
    I was just wondering how I can remove the highlighting when I select a Group Tree item.
    For example, when I select an item in the Group Tree, the report returns with the selected item "highlighted".
    Is there a way to remove the highlight?
    Thanks for any help with this.
    JohnMc
    Edited by: JohnMc3 on Jun 1, 2011 3:49 PM

    Hi John,
    Sorry I got ahead of myself. What I was suggesting is if you click anywhere else in the viewer the highlight is removed. I was looking/thinking if an event could be triggered to set focus somewhere else the highlight would be removed.
    Other than that I don't see any other way. Odd your users don't want to see what they clicked on... What ever you are used to I guess....
    No option directly. If you want add your request to Idea Place and the PM's will look into it.
    Just thought of something else, Hide the Group Tree and create your own, then you have full control over what it looks like. Lots of work for a minor appearance preference though...
    Thanks
    Don
    Edited by: Don Williams on Jun 2, 2011 6:42 AM

  • Tree selection by user or programmatically

    Hallow All!
    How can I know if tree selection mode by user or programmatically?
    I want to listen - tree selection and do some operation only if the selection made by user (mouse or keyboard) and do nothing if the selection made programmtically!
    I tried to use isFocusOwner methos:
    addTreeSelectionListener(new TreeSelectionListener() {
                   public void valueChanged(TreeSelectionEvent e) {
                        if(!TopologyTree.this.isFocusOwner()){
                             return;
    }but is doesn't work, if some text field in another panel has the focus then the tree gain the focus only after the tree selection event performed
    any help will be most appreciated!
    Eran.

    Create a substitution rule in which user name from the header is substituted to any of the fields in vendor line item. (assignment, text etc). After this you can use this for APP.
    Tarun

  • Tree, select leaf

    I use a xml-file in a Tree-component. The xml-files has
    nodes, and each node has some properties (type, id, label). I can
    use the code below to read the selected item in the tree.
    var xmlStr:String = myTree.selectedItem.toString();
    var xmlDoc:XMLDocument = new XMLDocument(xmlStr);
    var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
    var resultObj:Object = decoder.decodeXML(xmlDoc);
    id = resultObj.node.id;
    This works unless I am selecting an item at the end of the
    tree (the leaf). Then the object is empty.

    Please create a test case using local XML data and file a bug
    at bugs.adobe.com/jira in the Flex project

  • Using checkboxes to select items in a Spark DataGroup/List?

    I have a DataGroup from Catalyst, laid out like a tile list:
    I'd like to do something a bit different, in that I'd like to allow people to multi-select items in the list using those checkboxes instead of the usual command/control-click.
    The checkbox, label and image are in the itemRenderer.  Is there an easy way that I can have that checkbox toggle the selected state of its list item?

    Hi,
    Using the checkbox as a selection is easy enough as all you have to do is add a change event to the checkbox in the renderer and then in the event
    selected=mycheckbox.selected;
    The fun is how to handle the list click event from the checkbox you can stop propagation but if the item is clicked it will reset the selected indices.
    There is a few ways to handle this
    when processing the list don't use the selected indices just use the checkbox value to determine whats selected
    disable the listbox click event so items have to be selected with the checkbox
    or the most complex lots of overriding so that click acts like a ctrl/click and the checkbox/itemclick can toggle each other.
    David

  • Combox Box not displaying selected item

    Below is the code I'm using to try to capture and display the
    selected item from a ComboBox:
    private function
    changeProjectTypeSelection(event:Event):void{
    projectTypeChange.text+=event.currentTarget.selectedItem.cboProjectType
    + " " +
    event.currentTarget.selectedIndex + "\n";
    Then the ComboBox:
    <mx:ComboBox fontSize="12" x="93" y="83" width="110"
    id="cboProjectType" dataProvider="{projectTypeArray}"
    labelField="projectTypeName" selectedIndex="0"
    click="changeProjectTypeSelection(event)"></mx:ComboBox>
    Then the TextInput:
    <mx:TextInput id="projectTypeChange" x="248.95" y="84"
    width="121"/>
    I know there's something wrong with the Actionscript code...
    just haven't figured it out. Any suggestions would be greatly
    appreciated!

    I've almost got it...
    private function
    changeProjectTypeSelection(event:Event):void{
    var i:int;
    for(i=0;i<projectTypeArray.length;i++){
    if(projectTypeArray.getItemAt(i).projectTypeName ==
    event.currentTarget.selectedItem.projectTypeName){
    projectTypeChange.text+=projectTypeArray.getItemAt(i).projectTypeName
    + "\n";
    Alert.show(projectTypeArray.getItemAt(i).projectTypeName +
    "FirstAlert");
    //Alert.show(event.currentTarget.selectedItem.projectTypeName +
    "SecondAlert");
    I just can't seem to be able to reset the value in the
    textInput field. I've tried setting it equal to spaces in several
    places, but it won't change after the first selection. Any ideas?
    Thanks for any suggestions!

Maybe you are looking for

  • Problems upgrading from Lion to Mountain Lion

    First of all, I greet you all. First time poster from Mexico. I´m having problems with certain applications since I updated from Lion to Mountain Lion. The transition has been filled with issues, specially with aspects related to the incorporation of

  • Reg DBIF_RSQL_SQL_ERROR -    CX_SY_OPEN_SQL_DB

    We are getting lot of below run time error while querying on TVARVC table in production system. Runtime Errors         DBIF_RSQL_SQL_ERROR Exception              CX_SY_OPEN_SQL_DB Database error text........: "SQL0911N The current transaction has bee

  • Submit button to local/network folder

    Goal: Place a Submit button on a PDF form that will save a copy of the entire form to a local/network folder. Software: Windows 7, Adobe Acrobat X Pro Per the Adobe Acrobat X Pro help files, it states that you can add a folder path in the URL field w

  • T500 headphones buzzing issue!

    I just bought a T500 used, and most sounds buzz with every pair of headphones I use, it's mainly the right ear. Does anyone know hwy this is happening? I have reinstalled drivers, and tried cleaning the headphone jack, but I can't make sounds stop bu

  • I've lost my itunes app.  how do i restore it?

    iTunes icon is no longer on the home screen.  I've tried re-syncing, but no luck. I've probably missed the obvious, but how do I get it back?  Cheers Richard