Access BindingContainer (Page Bindings) of another page using DataBindings.cpx in Oracle ADF

Sharing is Caring

Hello all
this post is about a requirement of getting page binding of another page that is not active currently
we use BindingContainer to access bindings of current page, region in the managed bean

Oracle Docs says-
The BindingContainer contains the Control Bindings for a reusable unit of View technology. For example, each individual Page, Region, or Panel refers to a unique BindingContainer with a set of Control Bindings that refer to the Model elements used by that Page. The BindingContainer interface is implemented by the data binding framework provider. 

So to access operations, methods exposed in the client, listBinding, IteratorBinding we need to get BindingContainer of current viewport (a page or a page fragment)
this method is used to get Binding Container –

import oracle.adf.model.BindingContext;
import oracle.binding.BindingContainer;

    /*****Generic Method to get BindingContainer of current page, fragment or region**/
    public BindingContainer getBindingsCont() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

as previously mentioned that BindingContainer contains bindings of current page but sometimes we need to access Binding Container of any other page in order to access its operations, iterators

So how to do this?

for this, I have created 2-page fragments inside a bounded task flow

 

firstPage is very simple , it has only one button and secodPage has Departments (HR Schema ) viewObject as a form

First Page Second Page

then I added createInsert operation in second-page binding, so here is the pageDef of the second page
as there are no bindings on the first page so there is no pageDef file is generated for that

 

now what I want to do is to call createInsert operation of Departments viewObject from the first page, but there is no binding of operation in the first page so if I use

BindingContext.getCurrent().getCurrentBindingsEntry()

to get BindingContainer then it will throw NullPointerException on calling createInsert

Now i have to get Binding Container of secondPage –
Go to DataBindings.cpx file and see usageId for the second page

 

Copy page usageId from there

BindingContainer

pass this usageId in this method to get Binding Container of the second page

    /**
     * @param data
     * @return
     */
    public Object resolvEl(String data) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
        Object Message = valueExp.getValue(elContext);
        return Message;
    }

    /**Method to get BindingContainer of Another page ,pageUsageId is the usageId of page defined in DataBindings.cpx file
 * @param pageUsageId
 * @return
 */
    public BindingContainer getBindingsContOfOtherPage(String pageUsageId) {
        return (BindingContainer) resolvEl("#{data." + pageUsageId + "}");
}

then call createInsert operation using this Binding Container

 getBindingsContOfOtherPage("binidngs_view_secondPagePageDef").getOperationBinding("CreateInsert").execute();

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “Access BindingContainer (Page Bindings) of another page using DataBindings.cpx in Oracle ADF”

  1. Thanks for acticle!
    This work for me
    getBindingsContOfOtherPage("view_choosePeriodViewPageDef").getOperationBinding("DeletePayroll").execute();

    But when I'm trying to get attribute binding I'm getting -1. Could you tell me why?
    getBindingsContOfOtherPage("view_choosePeriodViewPageDef").getControlBinding("PeriodName").toString();

Leave a Reply

Your email address will not be published. Required fields are marked *