Tuesday, July 10, 2012

How to get Selected Value or Selected Index from SelectManyChoice ADF Component



af:selectManyChoice : This component is very useful especially if you have a requirement to display a list values and provide the option to select more than one value from the drop down. For each item displayed as part of List will have a Check box, so that user can select more than one check box from the drop down list.






How to make this component on Page fragment ?  Create a View Object on model layer, and drag it as selectManyChoice on to the page fragment.








Write a java method in backing bean as below to fetch selected values or indices.

    BindingContext bc = BindingContext.getCurrent();
    DCBindingContainer binding =
      (DCBindingContainer) bc.getCurrentBindingsEntry();
    JUCtrlListBinding splHandlBinding =
      (JUCtrlListBinding) binding.get("SpecialHndlgLOVVA");
    Object[] splHandling = splHandlBinding.getSelectedValues();


Here is the code to get selected indices values



    BindingContext bc = BindingContext.getCurrent();
    DCBindingContainer binding =
      (DCBindingContainer) bc.getCurrentBindingsEntry();
    JUCtrlListBinding splHandlBinding =
      (JUCtrlListBinding) binding.get("SpecialHndlgLOVVA");
    Object[] splHandling = splHandlBinding.getSelectedIndices();






3 comments:

  1. Hello Ravi, how are you ?

    I did some looking until i found your article but my array splHandling is not getting me any values and i need your help finding why, if you can please (size of the array = 0).

    My source code is this:
    (SelectManyCheckbox instead of Many choice but i tried with both)




    Bean Method (copy paste from yours)
    public void checkboxteste(ValueChangeEvent valueChangeEvent) {

    BindingContext bc = BindingContext.getCurrent();
    DCBindingContainer binding = (DCBindingContainer) bc.getCurrentBindingsEntry();
    JUCtrlListBinding splHandlBinding = (JUCtrlListBinding) binding.get("LocationsView1");
    Object[] splHandling = splHandlBinding.getSelectedValues();
    System.out.println("size: " + splHandling.length);
    for (int i=0; i < splHandling.length;i++) {
    System.out.println(splHandling[i].toString());
    }
    }

    My array is giving 0 for the size, so its not detecting my selections.
    Can you help me please? I'm using Jdeveloper 12.1.2.0.0
    My email is: f.barracha@gmail.com

    Regards,
    Frederico

    ReplyDelete
  2. I already found the error i was getting.

    For anyone with the same error, you have to change your checkbox list (in the page definition) to work with ListIndex instead of ListObject.

    Regards,
    Frederico.

    ReplyDelete
  3. Hello Ravi,
    Can you helpt me?
    1. I created one viewCriteria for ViewObject, created view criteria and criteria item with support Multiple Value Selection.
    2. I drag and Drop view criteria from View object to jspx page, UIComponent as af:query
    3. I wrote manage Bean to get value generate when runtime in af:query, but value return as formate getClass.getName()+'@'+Integer.toHexString(hashCode()), they are the same index' value, not as value exactly.
    So, How Do I get List of Value from selectManyChoice?
    Thanks alot

    ReplyDelete