Create new look up data using List of Values (LOVs) in Oracle ADF

Sharing is Caring

While working on the project, I have seen such type of List of Values (LOV) that have an option of creating Lov Value at selection time, this is quite good, as if desired value is not available in the list then the user can create on that time.

This type of list looks like this

It means if there is no company available on the list you need not to go on Company form, the user can create it directly from here.
Doing this in ADF is quite simple, in this tutorial I am taking the example of Oracle default HR schema (Employees and Departments) table-
Implementation Steps-

  • Create business components from Department and Employees tabl

 

 

  •  Now create LOV on DepartmentId of employees ViewObject from Department VO
List of Values

 

  •  Now drag fields of Employee from DataControl to page as the form
  •  Select Department Id Lov and go to structure window, and drop a link in customActions facet of  af:inputComboboxListOfValues
  • Now drag a popup on the page and drag Department VO on af:dialog as a form to create the new department. and other things are same as a normal form

 

  • Bind this popup to bean and create a ActionListener on the link inside facet to invoke createInsert of department table

package lookup.view.bean;

import java.io.Serializable;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import oracle.adf.model.BindingContext;

import oracle.adf.view.rich.component.rich.RichPopup;

import oracle.adf.view.rich.event.DialogEvent;

import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;

import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;

public class LookupDataBean implements Serializable {
private RichPopup deptPopUpBind;

public LookupDataBean() {
}

public BindingContainer getBindings() {
return BindingContext.getCurrent().getCurrentBindingsEntry();
}

private void showPopup(RichPopup pop, boolean visible) {
try {
FacesContext context = FacesContext.getCurrentInstance();
if (context != null && pop != null) {
String popupId = pop.getClientId(context);
if (popupId != null) {
StringBuilder script = new StringBuilder();
script.append("var popup = AdfPage.PAGE.findComponent('").append(popupId).append("'); ");
if (visible) {
script.append("if (!popup.isPopupVisible()) { ").append("popup.show();}");
} else {
script.append("if (popup.isPopupVisible()) { ").append("popup.hide();}");
}
ExtendedRenderKitService erks =
Service.getService(context.getRenderKit(), ExtendedRenderKitService.class);
erks.addScript(context, script.toString());
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public void createDept(ActionEvent actionEvent) {
BindingContainer bindings = getBindings();
OperationBinding ob = bindings.getOperationBinding("CreateInsert");
ob.execute();
showPopup(deptPopUpBind, true);
}

public void DeptDialogListener(DialogEvent dialogEvent) {
FacesContext fct = FacesContext.getCurrentInstance();
if (dialogEvent.getOutcome().name().equals("ok")) {
BindingContainer bindings = getBindings();
OperationBinding ob = bindings.getOperationBinding("Commit");
ob.execute();

}
}

public void setDeptPopUpBind(RichPopup deptPopUpBind) {
this.deptPopUpBind = deptPopUpBind;
}

public RichPopup getDeptPopUpBind() {
return deptPopUpBind;
}
}

 

  • Now run this application and click on Lov of DepartmentId, you will see your link there to create Department

 

 

  • Now see that how many departments are listed currently in LOV

 

  • Now click on Add Department link and add a department
  •  Again see the listed departments- Oracle ADF Tutorial is added in now list

this is how you can use this beautiful feature in your LOV-
Sample ADF Application- Download

Cheers 🙂 Happy Learning

Related Posts

I’m an Oracle ACE, Blogger, Reviewer,
Technical Lead working on Oracle ADF

0 thoughts on “Create new look up data using List of Values (LOVs) in Oracle ADF”

  1. How do I get the af:inputComboboxListOfValues to be refreshed after adding? I tried AdfFacesContext.getCurrentInstance().addPartialTarget() but not working.

Leave a Reply

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