Programmatically Select all values in ADF BC based selectMany (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle) component

Sharing is Caring

In this post, We’ll see how to Select all values in a component programmatically on an event like button click, value change event etc.
Previously i have posted a lot about component that supports multiple selection in ADF Faces (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle)
– Multiple Selection in ADF Faces
Note that this post is designed for ADF BC (viewObject) based components , to set values in bean based component check this-
Programmatically populate values in ADF Faces multiSelect component (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle) So for this i have just dropped Departments viewObject as multiSelect component on page
(af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle)

 

Page bindings section looks like this-

Now see the code written in Set all values as selected button-

    /**Method to get BindingContainer of current viewPort (page)
     * @return
     */
    public BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

/**Method to set all values as selected in SelectMany Components.
 * @param actionEvent
 */

public void setAllValuesToSelected(ActionEvent actionEvent) {

int arrIndex[];
//Get the iterator binding of component
DCIteratorBinding deptIter = (DCIteratorBinding) getBindings().get("DepartmentsView1Iterator");
//Get viewObject from Iterator
ViewObject deptVo = deptIter.getViewObject();
//Get component list binding , component is directly based on this
JUCtrlListBinding list = (JUCtrlListBinding) getBindings().get("DepartmentsView1");
DCIteratorBinding iterList = list.getDCIteratorBinding();
RowSetIterator rsi = deptVo.createRowSetIterator(null);
int i = 0;
int rowCount = (int) deptVo.getEstimatedRowCount();
//Initialize array and set it's size (equal to number of rows in List)
arrIndex = new int[rowCount];
while (rsi.hasNext()) {
//Get viewObject next row from RowSetIterator
Row nextRow = rsi.next();
//Set this row as page iterator's current row
iterList.setCurrentRowWithKey(nextRow.getKey().toStringFormat(true));
//Now get index of this row
int indx = iterList.getCurrentRowIndexInRange();
//Add it to array
arrIndex[i] = indx;
i++;
}
rsi.closeRowSetIterator();
// Set as selected indices
list.setSelectedIndices(arrIndex);
}

All done, now run and check application, click on the button and see what happens?

Select all values

Great, it’s working 🙂
I have explained one more approach to set values in multi-select components. In that approach, I have used component binding reference of ui components.
check it – Set values in af:selectManyChoice programmatically – Oracle ADF

Sample ADF Application-Download
Cheers 🙂 Happy Learning

 

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

Leave a Reply

Your email address will not be published. Required fields are marked *