Please disable your adblock and script blockers to view this page

Search this blog

Monday 13 October 2014

Set values in af:selectManyChoice programmatically - Oracle ADF

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 page and on this button action ,  setting values in 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-

Downoad Sample Application
Thanks , Happy Learning :)

6 comments :

  1. 500 Internal Server Error
    java.lang.UnsupportedOperationException


    while running the application getting this issue please help me on this issue


    thanks

    ReplyDelete
  2. 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.

    ReplyDelete
    Replies
    1. and what is the error ?
      and are you setting values in selectManyChoice or getting ?

      Delete
    2. 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!!!!!

      Delete
  3. Hi Ashish,

    how to set the default values for selectManyChoice from programmatic VO?

    ReplyDelete