Monday, May 6, 2013

ADF Select Many Listbox / Select Many Checkbox LOV


Few days back ,I was looking for an inbuilt feature of multi-select LOV in ADF and was quite surprised that ADF does not have this feature as a part of available LOV bindings.We cannot bind the LOV's to a selectManyListBox directly.To Achieve this we need to use a managed bean to dispatch between the ADF binding layer and the multi select component.The ADF selectManyListbox component allows the user to select many values from a list of items. It can contain any number of <f:selectitem>, <f:selectitems>, or <af:selectitem> components, each of which represents an available option that the user may select.

A typical ADF Multi select LOV looks like this :

<af:selectmanylistbox required="yes" value="#{bean.aValue}">
  <f:selectitem itemlabel="Option1" itemvalue="1">
  <f:selectitem itemlabel="Option1" itemvalue="2">
</f:selectitem></f:selectitem></af:selectmanylistbox>


Step 1 :

 1) Prepare a List of items that your Multi select LOV holds in a Managed Bean.The SelectManyListbox and -Choice value property writes/reads its value to/from a List (e.g. ArrayList)



2) Drag and drop the selectManyListbox component from Jdev Component palette on to the page and bind it to the list created above from managed bean. After creating list it should look like below code .Also create an another list with getters and setters in the managed bean and bind to the value property of af:selectManyListbox manually.

  <af:selectManyListbox label="Label 1" id="sml1"
                              value="#{backingBeanScope.MultiSelect.lovValue}">
          <f:selectItems
                         id="si2"
                         value="#{backingBeanScope.MultiSelect.actualList}"/>
  </af:selectManyListbox>




Now create an ADF button and action listener to a custom method in the managed bean.Inside the method write this code and you ll get the values which are being selected/checked by the user.



Input screen :





















After checking the required value click the commandbutton and in the jdev console you will see the output like this

Selected Value:ACTIVE
Selected Value:COMPLETED

All you need to do is when the getter is called you make sure the data is read from where it is created .when you write back take the list transform its entries in to the way you want. some may want to create comma delimited list of string,semi-colon separated ,individual strings which they want to store in DB .

ADF currently doesn't support binding the selectManyListBox value to the VO attribute directly this is the approach that I have followed as workaround!!

5 comments:

  1. can we get the sample project for the same

    ReplyDelete
    Replies
    1. hmm .. i have given complete code snippet.. u need to just put in the right place. i can assist u if u have any issue..

      Delete
    2. Hi Anantha,
      Can you tell me how can we achieve remove functionality of selected items. Would be of great help.

      Thanks,
      Animesh

      Delete
  2. Nice guide, just what i needed for my project. Thanks!

    ReplyDelete
  3. can we have a modified use case here. I will have a button here and name it remove selected. so user will select against the checkbox items and click on remove. Those items get completely removed. Any idea how to achieve this

    ReplyDelete