Friday, September 27, 2013

Synching a popup with a table row

Thursday, September 12, 2013

How to stretch an af:table

-> Drag and drop the table in the centre of the Panel Stretch Layout
-> and change the style class to AFStretchWidth Style Class

Monday, September 2, 2013

Managed Bean ( Concept ) / Calling a method in the AMImpl class from the Managed bean

Managed Bean : - It is a java class that is created in the view controller of the ADF application.
-> We can have one Managed bean for a task flow so that all the pages in the task flow can access that Managed bean.
-> In the over view of the task flow go to the managed bean and add the java class as a bean after we have created a java class in the view controller section of the application.
Note :- If we want to call a method in the backing bean from a page by setting it to a button action we have to add that method to the bindings of the page.

Call a method in the Application Module from the backing bean:-

import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.binding.BindingContainer;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import oracle.binding.OperationBinding;

  FacesContext facesContext = FacesContext.getCurrentInstance();
  Application app = facesContext.getApplication();
  ExpressionFactory elFactory = app.getExpressionFactory();
  ELContext elContext = facesContext.getELContext();
  ValueExpression valueExp =
    elFactory.createValueExpression(elContext, "#{bindings}", Object.class);
  BindingContainer binding= (BindingContainer)valueExp.getValue(elContext);
  // createCurrentCustomerRow is the name of the method in the AMImpl class
  OperationBinding operationBinding=binding.getOperationBinding("createCurrentCustomerRow");
  // Set the Input parameters to the operation bindings as below
     operationBinding.getParamsMap().put("pCustomerID", "100");  
  // Invoke the Application module method
  operationBinding.execute();
  // Get the result from operation bindings
  Object obj =operationBinding.getResult();

Sunday, September 1, 2013

List of Values/ Dependant List of Values

Suppose for employees table we want to create a list of values for the departmentId so that the user can select from the pre-existing set of drop down values and the various departments are available in the Department table.

-> create an EO and a VO for the employees
-> create an EO and a VO for the departments
-> In the EmplyeesViewObject.xml select the departmentId attribute in the Attributes section and add a new list of values. Select the List data source i.e., the VO from which we want to populate the list of values and the corresponding List attribute. This completes the creation of a list of values to the departmentId which come from the departmentsVO in the employeesVO

The above procedure is the same for creating dependant list of values. The query which populates the ManagerId should actually give the managerId straight away from the entered departmentId. For this create a VO which has a bind parameter (bindDepartmentId).

-> Initially for the ManagerId create a list of values with the above query.
-> Next step would be setting the bindDepartmentId to the departmentId.
-> In the View Accessors section click on the edit button of the VO. For the bind parameter set the value to      the DepartmentId which is the attribute from the EmployeesVO 

What does an AM contain? / How to add rows in a transientVO

Application Module contains the getter methods for the various view objects that are being exposed in the AM. Using which we can get the instances of the of the View Objects. For a transientVO we can call this method and add the attributes for a row.

method in the AM to add rows to a transientVO:-

public void addRows(){
 //get the instance of the view object
 TransientVOImpl vo = getTransientVO();
//get the instance of the transient row by using the VOImpl object
 TransientVORowImpl row = (TransientVORowImpl )vo.createRow();
 // set the attributes of the transientVO by using the setter methods in the RowImpl class of the VO
 row.setEmpId(id);
 row.setEmpName(name);
 row.setEmpSalary(salary);
  // insert the row
  vo.insertRow(row);
}

Programetically Iterating through the rows in a VO

-> ViewRowImpl class represents a row corresponding to the EO for which the VO has been created.
-> RowSet class represents the queried rows.

If suppose we want to iterate through the rows of the employees of a particular department and give a hike of some amount :-

public void applyEmpRise(Number rise){
  // Initially get all the rows from the employees
   RowSet emp = (RowSet)getEmployeeVO();
   while(emp.hasNext()){
    // when there are any rows in the table
    // get the current row using the VORowImpl
     EmpVORowImpl currentRow = (EmpVORowImpl)emp.Next();
     currentRow.setSalary(currentRow.getSalary().add(rise));  
   }
}