23 05 2008

ADF Faces / Access to Data Model from Backing/Managed Bean

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.
*
*
* MyPageBackingBean
* MyPageMB
* request
*
* bindings
* #{bindings}
*

*

*/
*/
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);
}

}


Links:

http://adf.webloji.net/

0 yorum: