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
|