Flipkart Search

Monday 5 May 2014

Useful methods in Oracle ADF. Part -1

1. Getting the VO

a.)  DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
            DCIteratorBinding dcIterBind = (DCIteratorBinding)dcBindings.get("VO1Iterator");  //VO1Iterator define in page def
            ViewObject vo = dcIterBind.getViewObject();
b.) AppModuleImpl amImpl= getApplicationModuleImpl();

     ViewObject vo=  amImpl.getVO();

2. Getting the Application module
a.)
ApplicationModule am=vo.getApplicationModule();
b.)
        FacesContext fc = FacesContext.getCurrentInstance();
        ValueBinding vb = fc.getApplication().createValueBinding("#{data}");
        BindingContext bc = (BindingContext)vb.getValue(fc);
        DCDataControl dc = bc.findDataControl("AppModuleDataControl");
        PublicPortalAppModuleImpl am = (PublicPortalAppModuleImpl)dc.getDataProvider();
3. Row count of a table
        RowSetIterator invoiceRsItr = dcIterBind.getRowSetIterator();
        System.out.println("invoiceRsItr.invoiceRsItr.getRowCount(): " +
                           invoiceRsItr.getRowCount()); 

4. Get URL parameter value
  public static String getURLParamVal(String pv_strParamerName) {
    HttpServletRequest objHttpServletRequest = (HttpServletRequest)getFacesContext().getExternalContext().getRequest();
    return objHttpServletRequest.getParameter(pv_strParamerName);
  }

5. Get operationBinding e.g.- RollBack , Commit etc
      public static OperationBinding getOperBinding(String operationName)
      {
      OperationBinding operBind=null;
      FacesContext fc = FacesContext.getCurrentInstance();
      ValueBinding vb = fc.getApplication().createValueBinding("#{bindings}");
      DCBindingContainer bindingContainer = (DCBindingContainer)vb.getValue(fc);
      oper = (OperationBinding)bindingContainer.getOperationBinding(operation);
      return operBind;
      } 

6. Get the selected rows for ADF table
      a.)  DCBindingContainer dcBindings =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dcIterBind =
            (DCIteratorBinding)dcBindings.get("EmployeesView1Iterator");
        RowSetIterator invoiceRsItr = dcIterBind.getRowSetIterator();
        RowKeySet rwkset1 = tableBind.getSelectedRowKeys();
        Iterator iter=rwkset1.iterator();
        Row row=null;
        while (iter.hasNext()) {
            Key key=(Key)((List)iter.next()).get(0);
            System.out.println("key "+key);
            row =
        invoiceRsItr.getRow(key);
            System.out.println("Email Selected-->" +
                               row.getAttribute("Email"));
        } 

Note: HR schema's employee table is used, tableBind is the binding of the UI adf table
b.)   
        Iterator iter = tableBind.getSelectedRowKeys().iterator();
        while (iter.hasNext()) {
            Object key= iter.next();
            tableBind.setRowKey(key);
            FacesCtrlHierNodeBinding rw = (FacesCtrlHierNodeBinding)tableBind.getRowData();
            System.out.println("Invoice Selected-->" +
                               rw.getAttribute("Email"));
            }

7. Selecting all rows of the table by a booleanCheckBox 

    public static void checkUncheckAll(String dcIteratorName, String rowName,
                                 String checkBoxVal) {
        DCBindingContainer dcBindings =
            (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        DCIteratorBinding dcIterBind =
            (DCIteratorBinding)dcBindings.get(dcIteratorName);
        RowSetIterator rsetIter = dcIterBind.getRowSetIterator();
        Row rw = null;
        boolean isFirst = true;
        while (rsetIter.hasNext()) {
            if (isFirst) {
                rw = rsetIter.first();
                isFirst = false;
            } else {
                rw = rsetIter.next();
            }
            rw.setAttribute(rowName, checkBoxVal);
        }
       // rsetIter.reset();    //reset to start the Iterator all over
        rsetIter.closeRowSetIterator();  //always remember to closeit-think it as resultset
    } 


Note:  dcIteratorName- name of VO iterator from Page Binding,VO column which has be implemented as checkBox,checkbox value-Boolean or Yes/No depending upon your logic
 8. Get the name of VOs exposed to the particular am
       String vonames[]= vo.getApplicationModule().getViewObjectNames();
        for (int i=0;i<vonames.length;i++){
            System.out.println(vonames[i]);
        }

No comments:

Post a Comment