This post is about a very common question
How to set selected values in af:selectManyChoice component?
Sometimes we need to set some values in selectManyChoice component on some action
In this post, I am using Departments table of HR Schema to create selectManyChoice (Multiple Selection)
Just drag and drop Departments viewObject as ADF Select Many Choice
see- Using Multiple Selection (selectManyListbox & selectManyCheckbox component) in ADF
(Jdev Version- 12.1.3)
dropped a button on the page and on this button action, setting values in the component
See this simple managed bean code –
import java.util.ArrayList; import javax.faces.event.ActionEvent; import oracle.adf.view.rich.component.rich.input.RichSelectManyChoice; import oracle.adf.view.rich.context.AdfFacesContext; public class SetValueSmcBean { private RichSelectManyChoice selectMcBind; public SetValueSmcBean() { } /**Methos to set selected values in SelectManyChoice * @param actionEvent */ public void setSelectedValuesAction(ActionEvent actionEvent) { ArrayList listVal = new ArrayList(20); //Add DepartmentId to list that you want to set as selected listVal.add(101); listVal.add(102); // Set this List as value using component binding selectMcBind.setValue(listVal.toArray()); //Refresh Component on page (partial target) AdfFacesContext.getCurrentInstance().addPartialTarget(selectMcBind); } public void setSelectMcBind(RichSelectManyChoice selectMcBind) { this.selectMcBind = selectMcBind; } public RichSelectManyChoice getSelectMcBind() { return selectMcBind; } }
run application and check-
Sample ADF Application- Download
Cheers 🙂 Happy Learning
500 Internal Server Error
java.lang.UnsupportedOperationException
while running the application getting this issue please help me on this issue
thanks
Download again and check and let me know
Thanks for the Blog ,It helped me in my project.
But after getting the selected element in the selectManyChoice Box while commiting on the same page this component shows error and does not let me to proceed unless i select something in selectManyChoice box manually.
Error:-
Please Help!!!!!!!!!!!
Thanks.
and what is the error ?
and are you setting values in selectManyChoice or getting ?
Hi Ashish,
how to set the default values for selectManyChoice from programmatic VO?
Gracias por el Blog. Me ayudó en mi proyecto.
Pero después de obtener el elemento seleccionado en el cuadro selectManyChoice al comprometerse en la misma página, este componente muestra un error y no me permite continuar a menos que seleccione manualmente algo en el cuadro selectManyChoice.
help!!!!!