Getting selected row in inputListOfValues returnPopupListener

Posted by Frank Nimphius on Oracle Blogs See other posts from Oracle Blogs or by Frank Nimphius
Published on Sun, 19 Jun 2011 23:33:48 -0700 Indexed on 2011/06/20 16:32 UTC
Read the original article Hit count: 742

Filed under:

Model driven list-of-values in Oracle ADF are configured on the ADF Business component attribute which should be updated with the user value selection. The value lookup can be configured to be displayed as a select list, combo box, input list of values or combo box with list of values.

Displaying the list in an af:inputListOfValues component shows the attribute value in an input text field and with an icon attached to it for the user to launch the list-of-values dialog.

The list-of-values dialog allows users to use a search form to filter the lookup data list and to select an entry, which return value then is added as the value of the af:inputListOfValues component.

Note: The model driven LOV can be configured in ADF Business Components to update multiple attributes with the user selection, though the most common use case is to update the value of a single attribute.

A question on OTN was how to access the row of the selected return value on the ADF Faces front end. For this, you need to know that there is a Model property defined on the af:inputListOfValues that references the ListOfValuesModel implementation in the model. It is the value of this Model property that you need to get access to.

The af:inputListOfValues has a ReturnPopupListener property that you can use to configure a managed bean method to receive notification when the user closes the LOV popup dialog by selecting the Ok button. This listener is not triggered when the cancel button is pressed. The managed bean signature can be created declaratively in Oracle JDeveloper 11g using the Edit option in the context menu next to the ReturnPopupListener field in the PropertyInspector. The empty method signature looks as shown below

public void returnListener(ReturnPopupEvent returnPopupEvent) { }

The ReturnPopupEvent object gives you access the RichInputListOfValues component instance, which represents the af:inputListOfValues component at runtime. From here you access the Model property of the component to then get a handle to the CollectionModel.

The CollectionModel returns an instance of JUCtrlHierBinding in its getWrappedData method. Though there is no tree binding definition for the list of values dialog defined in the PageDef, it exists. Once you have access to this, you can read the row the user selected in the list of values dialog. See the following code:

public void returnListener(ReturnPopupEvent returnPopupEvent) {  
  //access UI component instance from return event
  RichInputListOfValues lovField = 
       (RichInputListOfValues)returnPopupEvent.getSource();
  
  //The LOVModel gives us access to the Collection Model and 
  //ADF tree binding used to populate the lookup table
  ListOfValuesModel lovModel =  lovField.getModel();
  CollectionModel collectionModel =
         lovModel.getTableModel().getCollectionModel();   
  
  //The collection model wraps an instance of the ADF 
  //FacesCtrlHierBinding, which is casted to JUCtrlHierBinding
  JUCtrlHierBinding treeBinding =   
         (JUCtrlHierBinding) collectionModel.getWrappedData();
  
  //the selected rows are defined in a RowKeySet.As the LOV table only
  //supports single selections, there is only one entry in the rks
  RowKeySet rks = (RowKeySet) returnPopupEvent.getReturnValue();
  
  //the ADF Faces table row key is a list. The list contains the 
  //oracle.jbo.Key
  List tableRowKey = (List) rks.iterator().next();
  
  //get the iterator binding for the LOV lookup table binding  
  DCIteratorBinding dciter = treeBinding.getDCIteratorBinding();
  
  //get the selected row by its JBO key  
  Key key = (Key) tableRowKey.get(0);
  Row rw =  dciter.findRowByKeyString(key.toStringFormat(true));

  //work with the row
  // ...

}

© Oracle Blogs or respective owner

Related posts about /Oracle/ADFm