Programmatically populate values in ADF Faces multiSelect component (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle)

Sharing is Caring

ADF Faces provides some components to support multiple selection, ADF Faces multiSelect component is af:selectManyListbox, af:selectManyCheckbox, af:selectManyChoice, af:selectManyShuttle
In this post, we will see how to populate values in these components from the managed bean using POJO
You can read my previous post on multiple selections that was about populating multi-select component using ADF BC and the binding layer
Using Multiple Selection (selectManyListbox & selectManyCheckbox component) in ADF
Shuttle Component in Oracle ADF (Allow Multiple Selection)

See the step by step implementation-

    • Create a Fusion Web Application and a managed bean in viewController

 

    • Create a variable of type java.util.List in the managed bean, and generate its accessors

//List to show records in selectMany components
List<SelectItem> allValuesList;

public void setAllValuesList(List<SelectItem> allValuesList) {
this.allValuesList = allValuesList;
}

public List<SelectItem> getAllValuesList() {
return allValuesList;
}

 

    • This list contains value of type javax.faces.model.SelectItem; that is supported by af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox compoent

//List to show records in selectMany components

List<SelectItem> allValuesList;

public void setAllValuesList(List<SelectItem> allValuesList) {
this.allValuesList = allValuesList;
}

public List<SelectItem> getAllValuesList() {
if (allValuesList == null) {
allValuesList = new ArrayList<SelectItem>();
allValuesList.add(new SelectItem(1, "India"));
allValuesList.add(new SelectItem(2, "Australia"));
allValuesList.add(new SelectItem(3, "America"));
allValuesList.add(new SelectItem(4, "United Kingdom"));
}
return allValuesList;
}

 

    • See how to add this list reference to  af:selectManyCheckbox component, just drag n drop the component on the page

 

 

    • Set managed bean list reference to the selectManyCheckbox component, records stored in this list will be populated in component

 

 

    • Suppose I have to show some record as selected by default on page load so for this requirement created another List in managed bean and added it to value property of selectManyCheckbox component
      Value property of component refers only selected records but selectItems component refers all records of component

//List to show selected values in selectMany Component

List selectedValues;

public void setSelectedValues(List selectedValues) {
this.selectedValues = selectedValues;
}

public List getSelectedValues() {
if (selectedValues == null) {
selectedValues = new ArrayList();
selectedValues.add(1);
selectedValues.add(3);
System.out.println("List is-" + selectedValues);
}
return selectedValues;
}

See af:selectManyCheckbox source –

<af:selectManyCheckbox id="smc1" value="#{viewScope.ProgSelectManyComp.selectedValues}">
                                    <f:selectItems value="#{viewScope.ProgSelectManyComp.allValuesList}" id="si1"/>
                                </af:selectManyCheckbox>

 

    • Now run this application and see component on the page

 

    • Following same steps I have three more component on the page, all 3 ADF faces component support multiple selections
      af:selectManyChoice
      <af:selectManyChoice label="Label 1" id="smc2"
                                                           value="#{viewScope.ProgSelectManyComp.selectedValues}"
                                                           simple="true">
                                          <f:selectItems value="#{viewScope.ProgSelectManyComp.allValuesList}" id="si2"/>
                                      </af:selectManyChoice>

      af:selectManyListbox-

      <af:selectManyListbox label="Label 1" id="sml1"
                                                            value="#{viewScope.ProgSelectManyComp.selectedValues}"
                                                            simple="true">
                                          <f:selectItems value="#{viewScope.ProgSelectManyComp.allValuesList}" id="si3"/>
                                      </af:selectManyListbox>

      af:selectManyShuttle-

       <af:selectManyShuttle label="Label 1" id="sos1" simple="true"
                                                             value="#{viewScope.ProgSelectManyComp.selectedValues}"
                                                             contentStyle="width:50px;">
                                          <f:selectItems value="#{viewScope.ProgSelectManyComp.allValuesList}" id="si4"/>
                                      </af:selectManyShuttle>

 

    • All 4 components on the page are populated using the same List, this is just an example to show that all 4 components share the same structure, run this application and see

 

ADF Faces multiSelect component

Thanks, Happy Learning 🙂
Download- Sample ADF Application

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “Programmatically populate values in ADF Faces multiSelect component (af:selectManyCheckbox, af:selectManyChoice, af:selectManyListbox, af:selectManyShuttle)”

Leave a Reply

Your email address will not be published. Required fields are marked *