How to access selected rows in an af:selectManyChoice component
By Frank Nimphius on Jan 18, 2012
To create an ADF bound select many choice component, drag a collection from the Data Controls panel to a JSF page. In the opened context menu, choose Multiple Selection | ADF Select Many Choice.
This generates the page source code similar to this:
<af:selectManyChoice value="#{bindings.allDepartments.inputValue}" label="#{bindings.allDepartments.label}" id="smc1"> <f:selectItems value="#{bindings.allDepartments.items}" id="si1"/> </af:selectManyChoice>
Note that the value property of the SelectManyChoice component pints to the sane list binding as the f:selectItems tag. To access the user selected values, you use a managed bean to access the ADF binding layer.
If you are only interested in the selected values, then you use code like shown below. Note that the sample I built used JDeveloper 11g R2, which is why the ID type is Integer. Doing the same with JDeveloper 11g R1 would require the casting to oracle.jbo.domain.Number for ID columns.
public String cb1_action() { BindingContext bctx = BindingContext.getCurrent(); BindingContainer bindings = bctx.getCurrentBindingsEntry(); JUCtrlListBinding allDepartsmentList = (JUCtrlListBinding) bindings.get("allDepartments"); Object[] selVals = allDepartsmentList.getSelectedValues(); for (int i = 0; i < selVals.length; i++) { Integer val = (Integer)selVals[i]; //... } return null; }
However, what if you wanted to know more about the selected list value; for example the value of another attribute of the selected row? In this case you use similar code, with a little change though. Instead of calling getSelectedValues(), the call is to getSelectedIndices().
public String cb1_action() { BindingContext bctx = BindingContext.getCurrent(); BindingContainer bindings = bctx.getCurrentBindingsEntry(); JUCtrlListBinding allDepartsmentList = (JUCtrlListBinding) bindings.get("allDepartments"); int[] selVals = allDepartsmentList.getSelectedIndices(); for (int indx : selVals ) { Row rw = allDepartsmentList.getRowAtRangeIndex(indx); //... do your stuff } return null; }