Friday, September 25, 2009

Dynamically changing multiselect to single select in Table in OAF

I would like to share a small piece of code, which recently a friend shared with me, this is a typical requirement, which might look too trivial at first shot, but is quite easy to implement. Suppose you have a table where in you have a requirement to have single or multi selection based on a dynamic conditon eg, some selection or press of a button you wanna change the multiselection to single selection and vice versa.

In such scenario, in the action of the event you redirect to same page and use following code in process request on the base of parameter you set in session/pagecontext :
// Hiding the Multiple Select Table Action and add single selection
OAAdvancedTableBean tabBean = (OAAdvancedTableBean)webBean.
findIndexedChildRecursive("[table item id]");

//Since the multiselect is at the end, get the total count -1 for removing
int count = tabBean.getIndexedChildCount(pageContext.getRenderingContext());
System.out.println("Child Count "+count);

OAMultipleSelectionBean sel = (OAMultipleSelectionBean)tabBean.getTableSelection();
OASingleSelectionBean singleSelection = new OASingleSelectionBean() ;

//Set the attribute for the single select

I hope this helps anybody who tries to implement such scenario!