Add and delete values in POJO based selectOneListbox/selectOneChoice in ADF

Sharing is Caring

Previously I have posted about populating selectOneChoice programmatically using POJO
Programmatically populate values in an af:selectOneChoice component in ADF

In the same way, we can populate values in POJO based selectOneListBox as both ADF Faces components are used for single selection and share the same structure.

Here I have used a List to populate values in selectOneListBox (For details read the complete article in the above link)
And to get selected value from af:selectOneListBox/selectOneChoice in bean- Used a String variable , created it’s accessors

//List DataStrucutre to populate values in selectOneListBox 

List<SelectItem> customList = new ArrayList<SelectItem>();

public void setCustomList(List<SelectItem> customList) {
this.customList = customList;

public List<SelectItem> getCustomList() {
return customList;

//String variable to hold selectOneListBox value

private String selectedVal;

public void setSelectedVal(String selectedVal) {
this.selectedVal = selectedVal;

public String getSelectedVal() {
return selectedVal;

And see here how both List and String variable is bound to af:selectOneListBox

<af:selectOneListbox id="sol1" contentStyle="width:150px;" size="10" value="#{viewScope.SelectOneListBoxBean.selectedVal}">
                                    <f:selectItems value="#{viewScope.SelectOneListBoxBean.customList}" id="si1" var="variable"/>

Now I have dropped an inputText and two buttons on the page to add and delete values from selectOneListBox. Created component binding for inputText to get Value in the managed bean

<af:panelGroupLayout id="pgl1" layout="vertical">
                            <af:inputText label="Enter value to add in Listbox" id="it1"
                            <af:button text="Add Record" id="b1"
                            <af:spacer width="0" height="10" id="s1"/>
                            <af:panelGroupLayout id="pgl2" layout="horizontal">
                                <af:selectOneListbox id="sol1" contentStyle="width:150px;" size="10"
                                                     partialTriggers="b1 b2">
                                    <f:selectItems value="#{viewScope.SelectOneListBoxBean.customList}" id="si1"/>
                                <af:button text="Delete" id="b2"


Now see the code for add and delete buttons, Add button actionListener get value from inputText using component binding and add it to List  and Delete button finds and deletes the selected value from List

 /**Method to add Record in List
  * @param actionEvent
 public void addValueInList(ActionEvent actionEvent) {
     //Get value from inputText using component binding
     if (itBind.getValue() != null) {
         //Add value in List
         customList.add(new SelectItem(itBind.getValue().toString()));

/**Method that check for selected value in List
 * @param items
 * @param value
 * @return
public SelectItem getItem(List<SelectItem> items, String value) {
for (SelectItem si : items) {
if (si.getValue().toString().equalsIgnoreCase(value)) {
return si;
return null;


/**Method to delete selected record from List
 * @param actionEvent
public void deleteSelectedValue(ActionEvent actionEvent) {
if (selectedVal != null) {
//Find and delete selected item from List
customList.remove(getItem(customList, selectedVal));

All Done 🙂 Run and check application
Enter a value in inputText and click on Add button, It is added in ListBox

Add 3 values and select second value to delete

POJO based selectOneListbox

Click on the delete button

Sample ADF Application – Download
Cheers 🙂 Happy Learning

Related Posts

Leave a Reply

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