Jason Bennett's Developer Corner

 






Click to see the XML version of this web page.

>


View David Jason Bennett's profile on LinkedIn

 

 

A Little About Jason Bennett ...

I've had an interest in publishing technical articles and HELPFUL code for a few years.  I am (by trade and hobby) a developer who specializes in Oracle technologies and web based architectures.  I have been an employee of both TUSC and Oracle Corporation.  My intent here is to share my ideas and coding experiences with the developer community as a whole.  As with all developers some of my ideas are great and some of them are ....  well you know.  Anyway, I hope you find something here that will aid in your endeavor, or spark a new idea. 

I am more than happy to assist with technical issues and will even write a little code if need be. If you find something on the site that is really useful and you'd like to make a contribution (absolutely up to you and absolutely not required), just click the "Make a Donation" button on the left!

Good luck and good coding !




  Friday, November 23, 2007


An ADF Faces Base Class for a Backing/Managed Bean

   Over the last few months, I've been working on an ADF based project for my current employer.  The project is my first venture into JSF and ADF.  In this time I've developed a little base class that I extend when creating a backing bean (or managed bean) for my pages.  The base class contains several helpful utility methods that I thought I would share.  Some of these I discovered for myself, and a few others were inspired by samples provided by folks like: Steve Muench, Frank Nimphius, and Jonas Jacobi.  I have put the code below.  Each method has a comment at the top to explain what the method does:

The Code ...

import javax.faces.application.Application;
import javax.faces.context.FacesContext;

import oracle.binding.OperationBinding;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCDataControl;
import oracle.adf.model.binding.DCIteratorBinding;

import oracle.adf.view.faces.component.core.data.CoreTable;

import oracle.adf.view.faces.context.AdfFacesContext;


import oracle.binding.BindingContainer;

import oracle.jbo.ApplicationModule;

import oracle.jbo.Row;
import oracle.jbo.RowSet;
import oracle.jbo.server.EntityImpl;
import oracle.jbo.RowSetIterator;
import oracle.jbo.ViewObject;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.uicli.binding.JUCtrlValueBindingRef;

public class ManagedBeanBase {
   
   
    /**
    * Contains page binding references
    * This can be populated manually or
    * automatically based on config setting
    * in faces-config.xml
    *
    * This is a sample of an entry you would put in
    * the faces-config.xml file.  Notice the 'managed-property'
    * tag with property name 'bindings'.  This property will be
    * set by the faces servlet using the setBindings method below.
    *
    * <managed-bean>
    * <managed-bean-name>MyPageBackingBean</managed-bean-name>
    * <managed-bean-class>MyPageMB</managed-bean-class>
    * <managed-bean-scope>request</managed-bean-scope>
    *   <managed-property>
    *    <property-name>bindings</property-name>
    *    <value>#{bindings}</value>
    *   </managed-property>
    * </managed-bean>
    */
    */
    protected  BindingContainer  bindings;
   
    public ManagedBeanBase() {
    }

    public BindingContainer getBindings() {

        return this.bindings;
    }
   
    public void setBindings(BindingContainer bindings) {
        this.bindings = bindings;
    }
   
    /**
    *  Use this to manually set page bindingings.
    */
    public void setBindings(){
        FacesContext context = FacesContext.getCurrentInstance();
        Application app = context.getApplication();
        bindings = (DCBindingContainer) app.getVariableResolver().resolveVariable(context, "bindings");
    }
   

    /**
    * Call this method to refresh the binding container
    * with any changes.
    */   
    protected void refreshBindingContainer(){
   
        DCBindingContainer dcBind = (DCBindingContainer)bindings;
        dcBind.refresh();
       
    }
   
    /**
    * This method is used the removed the currently selected
    * row from and ADF (JSF) table.  The method requires
    * that the table object be passed in as a parameter.
    */
    protected void deleteSelectedRow(CoreTable pageTable){
 
        JUCtrlValueBindingRef rwData = (JUCtrlValueBindingRef)pageTable.getSelectedRowData();
       
        Row rw = rwData.getRow();
       
        rw.remove();
       
    }
   
    /**
    * This method takes the name of a given iterator (as defined in the page def file)
    * and returns the current rowset.
    */
    protected RowSetIterator getRowSetIterator(String p_iterator){
        
        DCBindingContainer dcBind = (DCBindingContainer)bindings;
        DCIteratorBinding iterBind= (DCIteratorBinding)dcBind.get(p_iterator);
       
        return iterBind.getLovRowSetIterator();
       
       
    }
   
    /**
    * This method will return the ViewObject (object) associated
    * with a given iterator.
    */
    protected ViewObject getViewObjectFromIterator(String p_iterator){
       
        DCBindingContainer dcBind = (DCBindingContainer)bindings;
        DCIteratorBinding iterBind= (DCIteratorBinding)dcBind.get(p_iterator);
       
        return iterBind.getViewObject();
       
       
    }
   
    /**
    * This method will execute the query associated the view object
    * with which the iterator is associated.
    */
    protected void executeIterQuery(String p_iterator){
       
        DCBindingContainer dcBind = (DCBindingContainer)bindings;
    
        DCIteratorBinding iterBind= (DCIteratorBinding)dcBind.get(p_iterator);
       
        iterBind.executeQuery();
       
    }
   
    /**
     *   This method issues a rollback again the current transaction.
     */
    protected void rollbackCurrentChanges(){
        
        DCBindingContainer dcBind = (DCBindingContainer)bindings;
        dcBind.getDataControl().getApplicationModule().getTransaction().rollback();
       
    }


    /**
    * Manually add a page component to the partial target list
    * for partial page refresh.
    */
    protected void addPartialTarget(UIComponent p_target_object){
        AdfFacesContext.getCurrentInstance().addPartialTarget(p_target_object);
    }
   
}

 


12:39:11 PM    

Click here to visit the Radio UserLand website. © Copyright 2008Jason Bennett.
Last update: 8/28/2008; 9:46:39 PM.

November 2007
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Aug   Jan