Thursday, April 14, 2011

Some Important Property Attribute @ADF

1) Rendered: this looks an important property attribute. we can use it to make components visible/hidden based on EL expression in it.
For Eg.: If our search result have only one result, then we can remove the Next and Previous buttons. We need to add those button inside a panel container and change its renderes property to

#{bindings.MyIterator.estimatedRowCount >1}

2) FacetName: If we have two facets named 'Found' and 'NotFound' inside switcher, then we can set the facetname to following

#{bindings.TechniciansIterator.estimatedRowCount > 0 ? 'Found' : 'NotFound'}

Bindings Creation at Runtime @ADF

As part of configuring your project for working with Oracle ADF data binding, JDeveloper registers an additional handler that is triggered whenever a client requests a JSP page. This handler is listed in the standard J2EE web application configuration file (web.xml) of your ViewController project. It sets up the correct binding container for the current page based on the related ADF Model XML configuration files, and makes it accessible using the EL expression #{bindings}. During the subsequent handling of the web page request, the JSF standard dictates a predictable set of processing steps known as the page "lifecycle". 


At runtime, multiple objects (i.e., binding context, binding containers, and binding objects) are created in memory to hold binding information. The ADF binding context is a runtime map of all data controls and page definitions within the application. The binding context is the one object that lives in the HttpSession for each end user, accessible using the EL expression #{data}.

The group of bindings supporting the UI components on a page are described in a page definition file. The ADF Model layer uses this file at runtime to instantiate the page's bindings. These bindings are held in a request-scoped map called the binding container, accessible during each page request using the EL expression #{bindings}. This expression always evaluates to the binding container for the current page.



  • Binding Context
    • The binding context provides the data environment for your application. It contains all of the data controls and binding containers that your application can access.
    • The ADF lifecycle creates the ADF binding context from the application module,DataBindings.cpx, and page definition files. Binding context contains references that become data control or binding container objects on demand.
    • You can look up ApplicationModule from a managed bean using the BindingContext:
      BindingContext bc = BindingContext.getCurrent();
      DCDataControl dc = bc.findDataControl("AppModuleDataControl");
      ApplicationModule am = (ApplicationModule)dc.getDataProvider();
    • You can retrieve a ControlBinding named "producerMethod" via BindingContext in this way:
      DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
      JUCtrlActionBinding actionBnd =
      (JUCtrlActionBinding)bc.getControlBinding("producerMethod");
  • Binding Containers
    • A binding container holds value bindings and iterator bindings (or binding objects) for a page. It provides runtime access to all the ADF binding objects for a page.
At runtime, a web request for http://yourserver/yourapp/faces/some.jsp arrives from the client to the application server. The ADFBindingFilter (defined in web.xml) object looks for the ADF binding context in the HTTP session, and if it is not yet present, initializes it for the first time. If the appropriate binding container for the page has never been used before during the user's session, it is created. Also, if it is the first time an application module data control is referenced during the request, it acquires an instance of the application module from the application module pool. Then the control is forwarded to the page to be rendered. The UI components on the page access value bindings and iterator bindings in the page's binding container and render the formatted output to appear in the browser. Finally, the user sees the resulting page in the browser.

These objects in the ADF model layer provide runtime access to business services:
binding context object ( oracle.adf.model.BindingContext)
Defines a common namespace for use by the client application and allows all model objects to be exposed through a convenient root name. Each web page or Java panel registers with the binding context using the definition for the variable name binding.
data control interfaces ( oracle.adf.model.binding.DCDataControl)
Provides the client application with an interface into the model objects. One data control is needed to wrap the model objects of each business service configuration. Also, in the case of a JavaBeans model object, provides developers with direct access to the native object, when programmatic access is desired.
binding container objects ( oracle.adf.model.binding.DCBindingContainer)
Defines a container for data binding objects, including iterator bindings and control bindings. One binding container is created for each web page or Java panel, but may be reused in multiple pages and panels when they share the same data. The binding container object also lets you specify whether the page or panel is to be used in data entry mode or query mode.
iterator binding objects ( oracle.adf.model.binding.DCIteratorBinding)
Handles the events generated from the associated business service row iterator and sends the current row to individual control bindings to display current data. Iterator bindings can specify the number of rows to display in a web page.
control binding objects ( oracle.jbo.uicli.binding.JUControlBinding)
Defines the way a specific UI component interacts with the corresponding business service. For example, depending upon the control binding selection, a text field may be bound to an Oracle ADF Business Components view object attribute and display as an editable field or a static label. Or, if the business service attribute defines an enumerated list of values, the bound UI component might display a static list, a single-selection list, or a multi-selection list. Other, more complex UI components, such as table and graphs, are also supported by their own control bindings.
action binding objects ( oracle.jbo.uicli.binding.JUCtrlActionBinding)
At runtime, when the user initiates the action, using a button control, the action binding accesses the Oracle ADF binding context and initiates the specified action on the data objects of the selected collection. Action bindings can take parameters that will be passed to the controller to handle.


Random Codes @ADF

1) This method set Resolved Date to current date when status changes to resolved.
    public String EmpMyTasks_SubmitAction() {
        BindingContainer bindings = getBindings();
        DCIteratorBinding itrbinding = (DCIteratorBinding)bindings.get("EmpMyTasksTroubleView1Iterator");
        Row row=itrbinding.getCurrentRow();
        if(row.getAttribute("Status").toString().equals("Resolved"))
        {
          row.setAttribute("Resolveddate", new Date());  
        }
        OperationBinding operationBinding = bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        return null;
    }

2) Initialize AssignedDate to current date
      DCIteratorBinding itrbinding = (DCIteratorBinding)bindings.get("TroubleView1Iterator");
      Row row=itrbinding.getCurrentRow();
      System.out.println("Location is"+row.getAttribute("Location"));
      row.setAttribute("Assigneddate", new Date());

3) To add popup with message like welcome or error:

        FacesMessage msg=null;
        FacesContext fc=FacesContext.getCurrentInstance();

        msg=new FacesMessage("Error While Submit");
        fc.addMessage(null, msg);

4) To find task assigned to logged in user

        String troubleassignedto=ADFContext.getCurrent().getSecurityContext().getUserName();
        ApplicationModule appMod =Configuration.createRootApplicationModule("model.BC.App_Mod.AppModule", "AppModulelocal");
        ViewObject troubleview= appMod.findViewObject("EmpMyTasksTroubleView1");
        troubleview.setWhereClause("ASSIGNEDTO =: assignedtoname");
        troubleview.defineNamedWhereClauseParam("assignedtoname", null, null);
        troubleview.setNamedWhereClauseParam("assignedtoname", troubleassignedto);
        troubleview.executeQuery();
        AdfFacesContext fc= AdfFacesContext.getCurrentInstance();
        fc.addPartialTarget(emp_MyTasks_CompBinding);

Class Hierarchy@ADF


SQL Query based View Objects@ADF

while creating the View object based on sql query (read only access) i got two errors:

1) In the query "select * from suppliers where suppliers.supplier_id = :sid" i am getting
Error: missing in or out parameter at index:1
i don't know whts wrng. however just as a work around i used following query "select * from suppliers where suppliers.supplier_id = ?" and it worked.

2) Error: <Utils><buildFacesMessage> ADF: Adding the following JSF error message: Invalid column index java.sql.SQLException: Invalid column index
Solution: I got this error when i created two bind variables that i used in my query from VO->Query tab. The problem was, for first bind variable i used 1 as bind position. However bind position must start from zero (as per developer's logic :) ).

Monday, April 11, 2011

Pass parameter to beam using EL @ ADF

this is a nice article on how to pass parameters to managed bean using EL. Three different options have been specified:

1) Memory attributes, 2) The ADF binding layer, 3) A setter/getter method on a managed bean that sets an internal variable.

http://blogs.oracle.com/jdevotnharvest/2011/04/passing_parameters_to_managed_bean_method_using_el.html

Tuesday, March 1, 2011

View Object Query Execution @ ADF

Like a read-only view object, an entity-based view object sends its SQL query straight to the database using the standard Java Database Connectivity (JDBC) API, and the database produces a result set. In contrast to its read-only counterpart, however, as the entity-based view object retrieves each row of the database result set, it partitions the row attributes based on which entity usage they relate to. This partitioning occurs by creating an entity object row of the appropriate type for each of the view object's entity usages, populating them with the relevant attributes retrieved by the query, and storing each of these entity rows in its respective entity cache. Then, rather than storing duplicate copies of the data, the view row simply points at the
entity row parts that comprise it.

The entity row that are brought into the cache using findByPrimaryKey() containes all attributes of the entity object. In contrast, an entity row created by partitioning rows from the View object query result contains values only for attributes that appear in the query. It does not include the complete set of attributes. This partially populated entity row represents an important runtime performance optimization.