5-16 Java EE Developers Guide for Oracle Application Development Framework
At runtime, when the tree control receives a selectionChanged event, it passes in the list of keys for each level of the tree. These keys uniquely identify the selected
node.
The tree binding starts at the top of the tree. For each tree level whose key is present in the Currently Selected Tree Node Keys list, if there is a TargetIterator
property configured for that nodeDefinition, the tree binding performs a setCurrentRowWithKey
operation on the selected target iterator. It uses the key from the appropriate level of the Currently Selected Tree Node Keys list.
5.6 Using Selection Events with Trees and Tables
There may be cases when you need to determine which node in a tree or tree table has been selected in order to handle some processing in your application. For example,
when a user selects a category node in a Browse tree, a selection event is fired. The listener associated with this event needs to determine the product category of the node
selected, and then to return all products whose category attribute matches that value.
5.6.1 How to Use Selection Events with Trees and Tables
To programmatically use selection events, you need to create a listener in a managed bean that will handle the selection event and perform the needed logic. You then need
to bind the selectionListener attribute of the tree or table to that listener.
To use selection events with trees and tables: 1.
If one does not already exist, create a managed bean to contain the needed listener.
2.
Create a listener method on the managed bean. For more information about creating listener methods, see the Using ADF Faces Server Events section of the
Oracle Fusion Middleware Web User Interface Developers Guide for Oracle Application Development Framework. Your listener should do the following:
a.
Access the component using the event source. Example 5–5
shows how the productCategoriesTreeSelectionListener
method on the HomeBean managed bean accesses the tree that launched the selection event.
Example 5–5 Getting the Source of an Event
public void productCategoriesTreeSelectionListenerSelectionEvent evt { RichTree tree = RichTreeevt.getSource;
For more information about finding the event source component, see the How to Return the Original Source of the Event section of the Oracle Fusion
Middleware Web User Interface Developers Guide for Oracle Application Development Framework.
b.
Access the tree model to get the value of the model, use the RowKeySet object to get the currently selected node, and then set that as the current row on the
model, as shown in Example 5–6
. For more information about RowKeySet objects, see
Section 5.6.2, What Happens at Runtime: RowKeySet Objects and SelectionEvent Events.
Example 5–6 Setting the Current Row on a Tree Model
TreeModel model = TreeModeltree.getValue; RowKeySet rowKeySet = evt.getAddedSet;
Object key = rowKeySet.iterator.next; model.setRowKeykey;
Displaying Master-Detail Data 5-17
c.
You can now add logic to execute against the currently selected row. For example, the productCategoriesTreeSelectionListener method uses
the value binding of the selected row to determine the category ID, and then uses that value as the parameter for another method that, when executed,
returns all products with that category ID, as shown in
Example 5–7 .
Example 5–7 Returning Objects That Match a Given Attribute Value
JUCtrlValueBinding nodeBinding = JUCtrlValueBindingmodel.getRowData;
Number catId = NumbernodeBinding.getAttributeCategoryId; _selectedCategory = StringnodeBinding.getAttributeCategoryName;
OperationBinding ob = ADFUtils.findOperationProductsByCategoriesExecuteWithParams;
ob.getParamsMap.putcategory, catId; ob.execute;
3.
On the associated JSF page, select the tree or table component. In the Property Inspector, expand the Behavior section and set the value of the
SelectionListener attribute to the listener method just created. You can use
the Edit option from the dropdown method to declaratively select the bean and the method.
5.6.2 What Happens at Runtime: RowKeySet Objects and SelectionEvent Events