Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label Look Up Data. Show all posts
Showing posts with label Look Up Data. Show all posts

Sunday 19 January 2014

Creating new object in list (af:inputListOfValues) using 'createPopupId' feature- ADF 11g & 12c

Hello All ,
This post is about a good feature provided with inputListOfValues in ADF .
inputListOfValues is used where large and complex data is populated in list, this component supports search in list values
Suppose on opening list values you want to add one more value in list generally to do that you will  close the list and add a value in source table then again open list but this feature provide instant creation of list values

this functionality can be achieved in Combo Box with List of Values using customActions facet, i have posted about it
Create new look up data using List of Values (LOVs) in Oracle ADF

so this time it is about  inputListOfValues, see the steps to do

  • Created a fusion web application and business components  using Departments and Employees table of HR Schema

  • now i have created list of values on DepartmentId of Employees ViewObject referenced from Department ViewObject, display type is Input Text with List of Values



  •  drop Employees VO on page and run, it looks like this

  • Now i have dropped a popup on page and to create new value in list, i have dropped form of Departments ViewObject and a link to create it on dialog inside popup
     

  • select list of values component (Employee VO) in structure window and go to property inspector and set popUp id in a property called 'createPopupId'
  • After setting 'createPopupId' ,on running a commandToolbarButton appears in the LOV popup dialog box with a icon, this button's action triggers custom popUp (i have added before)
        on clicking on this icon-

  •  on create link i have just called createInsert for Departments ViewObject and on dialogListener , Execute

  • import oracle.adf.model.BindingContext;
    import oracle.binding.BindingContainer;
    import oracle.binding.OperationBinding;
    
    
    
        /**Method to get Bindings of current page
         * @return
         */
        public BindingContainer getBindings(){
            return BindingContext.getCurrent().getCurrentBindingsEntry();
        }
    
        /**Method to execute OperationBinding
         * @param operation
         * @return
         */
        public OperationBinding executeOperation(String operation){
            return getBindings().getOperationBinding(operation);
        }
    
        /**Method to create new Department
         * @param actionEvent
         */
        public void createDeptAction(ActionEvent actionEvent) {
           executeOperation("CreateInsert").execute();
        }
    

  • now created a new department using 'create' link and you can see value is appeared in list values

 Cheers :-)

Monday 8 July 2013

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


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

This type of list looks like this


It means if there is no company available in list you need not to go on Company form, user can create it directly from here.
Doing this in ADF is quite simple , in this tutorial i am taking 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



  • Go to UI Hints tab of LOV and select Combo Box with List of Values

  •  Now drag fields of Employee from DataControl to page as 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 page and drag Department VO on af:dialog as form to create new department. and other things are same as 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