Tuesday, November 2, 2010

Programmatically Access Page Bindings

Using EL references bindings declaratively in ADF should always be followed, but there always is room for you to argument your application behavior in your own code.

Here I am summarizing to access page bindings programmatically.

How to access Page Definitions/Binding Context/Binding Container?

BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();

How to access page bindings in the page definition?

There are different types of bindings: attributeBinding, treeBinding, listBinding, actionBinding, methodBinding, etc
The corresponding types of codings have only two types: controlBinding and operationBinding. It's easy to recognize here. ActionBinding and methodBinding reference some actions and custom methods which are supposed to be executed somehow, therefore goes into the type of OperationBinding because it has execute() function. Other bindings are belonging to the valueBinding type so controlBinding is used.

The codings are:

OperationBinding oper = bc.getOperationBinding("actionMethodName");

We can also use JUCtrlActionBinding for actionBinding

ControlBinding cb = bc.getControlBinding("valueBindingName");

When using getControlBinding() method, we probably already know what type of valueBinding to access. So it usually is cast to the type of binding. For example,

1. attribute binding
AttributeBinding attr = (AttributeBinding)bc.getControlBinding("attrBindingName");

2. tree binding
JUCtrlHierBinding hierBinding = (JUCtrlHierBinding)bc.getControlBinding("treeBindingName");

Check here for the controlBinding implementing class.

No comments: