Tuesday, October 30, 2012

How to store values into various scopes in ADF

Subject :  How to store various values into various scopes(Application, PageFlow, Session, Request) in ADF

Solution

Setting values into various scopes


FacesContext fx =FacesContext.getCurrentInstance();

// Set Into Application Scope
ExternalContext exContext =fx.getExternalContext();
exContext.getApplicationMap().put("key","value");

// Set Into Request Scope
ExternalContext exContext =fx.getExternalContext();
exContext.getRequestMap().put("key","value");


// Set Into Session Scope
ExternalContext exContext =fx.getExternalContext();
exContext.getSessionMap().put("key","value");


// Set Into PageFlow Scope
RequestContext.getCurrentInstance().getPageFlowScope().put("key","value);

Retrieving Values.

RequestContext.getCurrentInstance().getPageFlowScope().get(name);

exContext.getApplicationMap().get("key");


Thursday, October 25, 2012

How to pass parameters to Popup Window in ADF


Subject :  How to pass parameters to a popup window. For eg : Page fragment displays employee details in a <af:table> format , By selecting any employee name for a specific row we are launching a popup and we need to pass the selected row specific employee name to popup window

Solution



<af:column id="c2" headerText="EmpName">
// Set clientComponent vlaue = true, define clientAttribute and set emp Name value
  <af:outputText value="EmpName" id="ot1" clientComponent="true">
     <af:clientAttribute name="empName" value="#{row.lastName}"/>
// Show popup when mou mouse Hover
     <af:showPopupBehavior popupId="::p1" triggerType="mouseHover"  
                           align="endAfter" alignId="ot1"/>
  </af:outputText>
</af:column>




<af:popup id="p1" launcherVar="source" contentDelivery="lazyUncached" eventContext="launcher">
     <af:panelFormLayout id="pfl1">
<af:panelLabelAndMessage label="EmployeeName" id="plam1">
<af:outputText value="#{viewScope.ename}" id="ot5"/>
</af:panelLabelAndMessage>
</af:panelFormLayout>
<af:setPropertyListener from="#{source.attributes.empName}" 
                           to="#{viewScope.ename}" type="popupFetch"/>
</af:popup>


Monday, October 22, 2012

How to get Filtered Rows in View Object using ADF


Subject :
 If you need to get a collection of rows from a view object based on some filtered criteria, Follow the below solution , To explain in detail For eg : You could have got 100 rows after performing a search on EmployeeROVO , But if you want to get rows from the EmployeeROVO only where employee status equals 'Active' , then you don't need to re query the view object , You can filter the rows from the row set itself

Solution #1


// Status & Qualification - Attribute name        
RowQualifier rq =
          new RowQualifier("Status= '" + row1.getEmpStatus() +
                           "' AND Qualification= '" +
                           row1.getQualification() + "'");

        Row[] rows = empVO.getFilteredRows(rq);

Solution #2

// First parameter is attribute name , Second attribute is value of the attribute that you want to filter
Row[] rows = empVO.getFilteredRows("Status","Active");

How to use findByKey() in ADF


Subject : 

   To find a specific row from a Row Set Iterator using findByKey() and setting the row as a current Row to a specific view object

Solution#1 - To get a specific row in Application Module Impl class


//Primary key value , Specify the data type accordingly
    String empID= "EMP001";
   
    // 1. Get the View Object instance
       EmployeeVO empVO = getEmployeeVO();
 
    // 2. Create a Key object
    Key key = new Key(new Object[] { empID });
   
    //3. Get the RowSetIterator Object
    RowSetIterator rsi = empVO.createRowSetIterator(null);
   
    //4. Find the row in the Iterator using findByKey funtion by passing Key object
    Row row = rsi.findByKey(key, 1)[0];
   
   // 6. Set the Current row in Iterator (findByKey does not Navigate to current row)
    rsi.setCurrentRow(row);


Solution#2 - To get a specific row in Managed Bean


//Primary key value , Specify the data type accordingly
    String empID= "EMP001";
   
    // 1. Access the binding container
    DCBindingContainer bc = (DCBindingContainer)getBindings();
 
   // 2. Find a named iterator binding
    DCIteratorBinding iter =
      (DCIteratorBinding)bc.findIteratorBinding("EmployeeVOIterator");
 
    // 3. Create a Key object
    Key key = new Key(new Object[] { empID});
   
    //4. Get the RowSetIterator Object
    RowSetIterator rsi = iter.getRowSetIterator();
   
    //5. Find the row in the Iterator using findByKey funtion by passing Key object
    Row row = rsi.findByKey(key, 1)[0];
   
   // 6. Set the Current row in Iterator (findByKey does not Navigate to current row)
    rsi.setCurrentRow(row);


 


Friday, October 19, 2012

How to Refresh an UI Component from Backing bean in ADF






   // Get the Component based on given UIComponent ID and refresh the component

    private static void refreshComponent(String pComponentID) {
        UIComponent component = findComponentInRoot(pComponentID);
        refreshComponent(component);
    }


    // Get Faces Context, Get Root Component, Find the given Component From the root component

    private static UIComponent findComponentInRoot(String pComponentID) {
        UIComponent component = null;
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext != null) {
            UIComponent root = facesContext.getViewRoot();
            component = findComponent(root, pComponentID);
        }
        return component;
    }


    // Refresh the Component

    private static void refreshComponent(UIComponent component) {
        if (component != null) {
            AdfFacesContext.getCurrentInstance().addPartialTarget(component);
        }
    }

   // Get the specific  component from a root component tree.

    private static UIComponent findComponent(UIComponent root, String id) {
        if (id.equals(root.getId()))
            return root;

        UIComponent children = null;
        UIComponent result = null;
        Iterator childrens = root.getFacetsAndChildren();
        while (childrens.hasNext() && (result == null)) {
            children = (UIComponent)childrens.next();
            if (id.equals(children.getId())) {
                result = children;
                break;
            }
            result = findComponent(children, id);
            if (result != null) {
                break;
            }
        }
        return result;
    }



Thursday, October 18, 2012

to_char() and to_date() functions in SQL



Very common usage especially while dealing with Date/Time columns while querying from database.

To update a specific date column with a specific Date and Time,


update employee set hire_date= to_date('101812 19:16:16', 'MMDDYY HH24:MI:SS' ) where emp_id=12

Similarly, If you want to to query Date column with Time stamp,

select to_char(hire_date,'MMDDYY HH24:MI:SS') from emp

Monday, October 8, 2012

If you are not seeing Top Line Filter for af:table

Though you have set sortable=true and filterable =true to your <af::table> component, sometimes you may still not find top line filters for <af:table> columns.

Below are the points, you may have to validate.

1.Define searchRegion in respective Page Definition


<searchRegion Binds="EmpViewIterator" Criteria=""
                  Customizer="oracle.jbo.uicli.binding.JUSearchBindingCustomizer"
                  id="EmpViewQuery"/>

2. Make sure <af:table> component should have below two attributes


       filterModel="#{bindings.EmpViewQuery.queryDescriptor}"
       queryListener="#{bindings.EmpViewQuery.processQuery}"


Tuesday, October 2, 2012

How to get Application Module Instance in Non ADF Projects



If you have a requirement to get instance of  an application module in Non ADF Projects , Follow the below code



import oracle.jbo.ApplicationModule;
import oracle.jbo.client.Configuration;


ApplicationModule am =Configuration.createRootApplicationModule("com.fm.model.emp.appmodule.EmployeeAppModule","EmployeeAppModuleLocal")


Note : This is not a best standard to follow in any of ADF related projects, This can be followed most likely in Web services or Junits.