Wednesday, April 21, 2010

Bit #14 - Using a Key to locate a Row in a View Object

Instead of iterating a View Object using a RowSetIterator - as described in Bit #4 - Iterating a View Object using a secondary RowSetIterator, you can locate a row directly using the ViewObject method findByKey(). This will work as long as you indicate a View Object attribute as a Key Attribute. To use this method, you will need to first instantiate a jbo.Key object and then pass it as an argument to findByKey(). findByKey() will return an array of rows that match the Key object. Special attention should be given when constructing Key objects for multi-part keys and for View Objects that are based on more than one Entity Objects. These cases are explained in detail in the Oracle Fusion Middleware Java API Reference for Oracle ADF Model documentation referenced below.

Example:

        // in the context of the ApplModuleImpl
      
        // locate the employee's department
        Number departmentId =
            ((EmployeesRowImpl)(this.getEmployees().getCurrentRow())).getDepartmentId();
        Key keyDepartment = new Key(new Object[] { departmentId });
      
        // the second argument indicates the maximum number of rows to return
        Row[] departments = this.getDepartments().findByKey(keyDepartment, 1);
        if (departments != null && departments.length > 0) {
            DepartmentsRowImpl department = (DepartmentsRowImpl)departments[0];
          
            // you can access the Department's attributes here....
        }

Context:

Application Module Implementation Class
View Object Implementation Class

Reference:

Oracle Fusion Middleware Java API Reference for Oracle ADF Model, findByKey

Monday, April 19, 2010

Bit #13 - Overriding create() to set the default value for a View Row attribute

One way to set the default value for a View Row attribute is to override its create() method in your custom View Row Implementation and call the attribute setter method to set its default value. Calling the attribute setter from inside the overridden create() method does not mark the new row as changed and it behaves like declaratively assigning a default value for the attribute. An example follows.

Example:

    @Override
    protected void create(AttributeList attributeList) {

        super.create(attributeList);

        // set main company's telephone number as default
        this.setPhoneNumber("6145551212");
    }


Context:

View Object Row Implementation

Sunday, April 18, 2010

Bit #12 - Accessing the authenticated user's security roles from a backing bean

To access the authenticated user's security roles from a backing bean, first retrieve the SecurityContext from the current ADFContext instance and then call its getUserRoles() method. getUserRoles() returns a String array of all the roles defined for the user. To determine whether a specific role is assigned to the user, call the  SecurityContext  isUserInRole() method specifying the role as an argument. This method will return a boolean indicator of whether the role is assigned to the user or not.


Example:

    // in the context of a backing bean

    public String[] getUserRoles(){
        return ADFContext.getCurrent().getSecurityContext().getUserRoles();
    }

    public boolean isUserInRole(){
        return ADFContext.getCurrent().getSecurityContext().isUserInRole("RoleName");
    }


Context:

Backing Bean


Reference:

Oracle Fusion Middleware Java API Reference for Oracle ADF Share, getUserRoles

Saturday, April 17, 2010

Bit #11 - Accessing an object stored at the PageFlowScope from a backing bean

You can access the PageFlowScope from a backing bean, by getting the AdfFacesContext instance and calling its getPageFlowScope() method. This will return the Map of all objects stored in the PageFlowScope. To retrieve a specific object, call get() on the Map specifying the object identifier. Similarly, call the getViewScope() and getProcessScope() methods of the AdfFacesContext to retrieve the ViewScope and ProcessScope respectively.

Example:

        // in the context of a backing bean
        Object data = AdfFacesContext.getCurrentInstance().getPageFlowScope().get("objectID");


Context:

Backing Bean


Reference:

Oracle Fusion Middleware Java API Reference for Oracle ADF Faces, getPageFlowScope

Thursday, April 15, 2010

Bit #10 - Selectively enabling Partial Page Rendering programmatically

You can selectively enable Partial Page Rendering (PPR) programmatically from a backing bean, by calling the AdfFacesContext method addPartialTarget(). To do so, simply bind the target component to the backing bean, get the AdfFacesContext  and call its addPartialTarget() method passing the bound component as a parameter. This will in effect rerender the component. The advantage of calling addPartialTarget() is that it will rerender the component selectively for the specific events that you choose.

Example:

    // in the context of the backing bean

    // bind the component to the backing bean
    private RichPanelBox panel;

    public void setPanel(RichPanelBox panel) {
        this.panel = panel;
    }

    public RichPanelBox getPanel() {
        return panel;
    }

    // rerender the component
    private void rerenderComponent() {
        AdfFacesContext.getCurrentInstance().addPartialTarget(this.panel);
    }

Context:

Backing Bean

Reference:

Oracle Fusion Middleware Java API Reference for Oracle ADF Faces, addPartialTarget

Tuesday, April 13, 2010

Bit #9 - Controlling the updatability of View Object attributes programmatically

The updatability of a View Object attribute can be controlled programmatically via the isAttributeUpdateable() method. When you look at its documentation, the declarative precedence that determines the attribute updatability should become clear. Programmatically, you override this method in your View Object Implementation Java file that you generate declaratively in JDeveloper. isAttributeUpdateable() is called for each attribute in the View Object. The index that is passed as an argument to the method determines the attribute index as it is returned by the AttributesEnum enumeration defined in the View Object Implementation source - for the specific attribute. To indicate that the specific attribute is updateable, isAttributeUpdateable() returns true; it returns false otherwise.

Example:

    @Override
    public boolean isAttributeUpdateable(int index) {
        boolean isUpdateable = super.isAttributeUpdateable(index);
        
        // do not allow updating first and last name
        if (index == FIRSTNAME || index == LASTNAME) {
            isUpdateable = false;
        }
        
        return isUpdateable;
    }

Context:

View Object Row Implementation

Reference:

Oracle Fusion Middleware Java API Reference for Oracle ADF Model, Row Interface


Friday, April 9, 2010

Bit #8 - Executing an operation binding programmatically from a backing bean

To access an OperationBinding in a backing bean, call getOperationBinding() on the DCBindingContainer - the data control binding container - and specify the operation binding identifier that you assigned to the operation during the declarative binding process. Once you have the OperationBinding call its execute() method to execute it. If you need to pass any arguments to the operation, call getParamsMap() to get the operation parameters map and put() on the map the specific argument. Call getResult() after the call to execute() to retrieve the result of the execution. Here is an example.


Example:

        // in the context of a backing bean

         OperationBinding operation = bindings.getOperationBinding("operation_name");

         operation.getParamsMap().put("parameter_name", parameterValue);

         operation.execute();

         if (operation.getResult() != null) {
                  Boolean result = (Boolean) operation.getResult(); // cast to the expected result type
        }


Context:

Backing Bean


Thursday, April 8, 2010

Bit #7 - Reseting the View Criteria associated with a View Object

To reset the View Criteria defined for a specific View Object, first you will need to retrieve the View Criteria from the View Object. You do this by calling the View Object method getViewCriteria() specifying the name of the View Criteria. This method will return a ViewCriteria object. Proceed with removing the criteria from the View Object by calling removeViewCriteria() on it. Call resetCriteria() on the ViewCriteria to reset them and finally re-apply the criteria to the View Object by calling applyViewCriteria() on it. Here is an example.

Example:

        // in the context of the Application Module Implementation

        ViewObjectImpl vo = this.getSomeViewObject();

        ViewCriteria vc = vo.getViewCriteria("criteria_name");
        vo.removeViewCriteria("criteria_name");

        vc.resetCriteria();
        vo.applyViewCriteria(vc);


Context:

Application Module Implementation
View Object Implementation


Wednesday, April 7, 2010

Bit #6 - Removing all rows from a View Object

To remove all rows from a View Object programmatically - i.e. clear or reset the View Object, call its executeEmptyRowSet() method. You can do this anywhere in the context of the Application Module or View Object Implementation.

Example:

    // in the context of the Application Module Implementation

   ViewObjectImpl vo = this.getSomeViewObject();
   vo.executeEmptyRowSet();


Context:

Application Module Implementation
View Object Implementation


Reference:

What Does executeEmptyRowSet() Do?

Tuesday, April 6, 2010

Bit #5 - Accessing a resource bundle from a backing bean

You can access a resource bundle from a backing by calling the getResourceBundle() method on a javax.faces.application.Application object and specifying the bundle name. You get the Application object by calling getApplication() on the FacesContext. The getResourceBundle() returns a ResourceBundle object. To get some resource data from the bundle, call getString() on the ResourceBundle specifying the resource identifier. The example below illustrates the case.

Example:


        FacesContext fc = FacesContext.getCurrentInstance();
        ResourceBundle bundle = fc.getApplication().getResourceBundle(fc,"bundle_name");
        bundle.getString("resource_identifier");


Context:

Resource Bundle
Backing Bean


Thursday, April 1, 2010

Bit #4 - Iterating a View Object using a secondary RowSetIterator

The recommended way to iterate a View Object is via a secondary RowSetIterator returned after calling createRowSetIterator() on the View Object. It is suggested to call reset() on the RowSetIterator before iterating it. This will move the currency to the slot before the first row. Iterate while calling hasNext() to check for next row availability and subsequently by calling next() to get the next row. When done, call closeRowSetIterator() to close the row set iterator. Failure to use a secondary RowSetIterator when directly iterating the View Object, could lead to end user confusion as the row set currency changes affecting the user interface.

Example:

// in the context of the AppModuleImpl

       RowSetIterator iterator = viewObject.createRowSetIterator(null);
       

       iterator.reset();

while (iterator.hasNext()) {
   Row row = iterator.next();
 

// process the row here
}

iterator.closeRowSetIterator();


Context:

Application Module Implementation class
View Object Implementation class


Reference:

Oracle® Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework 11g Release 1 (11.1.1) Part Number B31974-05 [Section 9.7.6 What You May Need to Know About Programmatic Row Set Iteration]

Related Posts Plugin for WordPress, Blogger...