Please disable your adblock and script blockers to view this page

Search this blog

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

Friday 5 July 2013

Changing af:convertNumber Format according to Locale- Oracle ADF

Simple post with very simple application-
we can covert a Numeric field format according to standard locale in ADF Faces.
when we have a numeric field on page there is a converter inside it, called af:convertNumber is extension of the standard JSF javax.faces.convert.NumberConverter.

 user can change it for Integer digits , fraction digits etc. but here i am talking about format of Number(Amount), to do this follow these steps.
  • Change GroupingUsed to true, by default it is true
  • Now set Locale, you can do this using managed bean or simply write it here
  • Managed Bean code to create Locale-  private Locale format=Locale.ENGLISH;
  • Now see various formats of Amount using Locale-



Using en-US-
 Using fr-
 Using hi-IN-for Hindi fonts
 Using de-DE -




so this is the thing how you can change formatting , this can also be done by managed bean.

  • Create a variable of type Locale and its getter -setter
  • Use it in Locale field of af:convertNumber  

  •     public void chinaButton(ActionEvent actionEvent) {
            this.setFormat(Locale.CHINA);
        }
        public void frenchButton(ActionEvent actionEvent) {
            this.setFormat(Locale.FRENCH);
        }
    
        public void italianButton(ActionEvent actionEvent) {
            this.setFormat(Locale.ITALIAN);
        }
    

  • You can also set Max and Min fraction digits in af:convertNumber

Wednesday 3 July 2013

Creating Dynamic View Object at Runtime programmatically - Oracle ADF

Dynamic ViewObject refers to creating ViewObject at Runtime using SQL statement,
ApplicationModuleImpl has a method to create ViewObject using Sql statement i;e createViewObjectFromQueryStmt .

this method creates a readonly viewObject at runtime when query is processed in the method

Follow these simple steps-

  • First create a dummy ViewObject using dual  


  • Now add this ViewObject to Application Module

  • I am doing this in managed bean, get application module and call method to create dynamic ViewObject
  •          get Application Module-




        public Object resolvElDC(String data) {
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();
            ValueExpression valueExp =
                elFactory.createValueExpression(elContext, "#{data." + data + ".dataProvider}", Object.class);
            return valueExp.getValue(elContext);
        }
    
        public dynamicAMImpl getAm() {
            dynamicAMImpl am = (dynamicAMImpl)resolvElDC("dynamicAMDataControl");
            return am;
        }
    

            create dynamic ViewObject-


            ViewObject dynVo = getAm().getdynamic1();
            dynVo.remove();
            getAm().createViewObjectFromQueryStmt("dynamic1", query);
    

  • Now Run your application and see-


Download -Sample ADF Application