How to access bindings from Java code in ADF

Maybe it’s me stupid, but I was looking for this for quite long and finally figured out how to. So I thought it could save someone’s time too.

Say we have a JSPX page bound to a ViewObject. Also there’s a backing bean for this page. What we want is to access from the backing bean a binding defined in the page definition.

So, there’s the faces-config.xml file in public_html/WEB-INF directory of ViewController project in where we define managed beans. A declaration of a managed bean called “testBean” pointing to the class com.datamoil.view.backing.Test with request scope would look like:

<managed-bean>
<managed-bean-name>testBean</managed-bean-name>
<managed-bean-class>com.datamoil.view.backing.Test</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

pretty simple, isn’t it? After this, the fields of that class can be accessed via EL expressions. Managed bean’s properties can be used from anywhere within the project using expression like #{testBean.<propertyName>}.

But to be able to use the bindings in the bean, there’s just another thing that must be done. Two things to be precise.

First, the managed bean declaration in faces-config.xml must include a managed-property element.

<managed-bean>
<managed-bean-name>testBean</managed-bean-name>
<managed-bean-class>com.datamoil.view.backing.Test</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>bindings</property-name>
<value>#{bindings}</value>
</managed-property>

</managed-bean>

Simple! This allows the bean to access the #{bindings} .

Second, it’s only left to create a field in the bean Java class.

//the field itself
oracle.binding.BindingContainer bindings;
//and its accessors
public void setBindings(oracle.binding.BindingContainer bindings) {
this.bindings = bindings;
}
public oracle.binding.BindingContainer getBindings() {
return bindings;
}

Amazingly simple as well. That’s pretty much it. Now thingies from the page definition can be accessed using Java code.

To e.g. get an Iterator called TestView1Iterator the code would be

oracle.jbo.uicli.binding.JUIteratorBinding testViewIter = (oracle.jbo.uicli.binding.JUIteratorBinding) this.bindings.get("TestView1Iterator");

or to get an Action called TestAction

oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding testAction = (oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding) this.bindings.get("TestAction");

Wonderful isn’t it? Just keep in mind that a binding is always looked up by its name/id, meaning there’s no guarantee one will be found. So in case there’s nothing under that name in the page definition, a NullPointerException will be thrown.

By using the bindings in managed beans application gets countless possibilities in functionality. For me at least, it was the greatest obstacle to start actually using ADF. I hope this helps! There’s also another way to access bindings, but be it another article about that way.



11 Responses to “ “How to access bindings from Java code in ADF”

  1. stratosg says:

    hey this is eli’s post! welcome back man ;) can’t wait for more of your posts!

  2. Siddharth says:

    I mean welcome back man :mrgreen:

  3. Germz says:

    Nice post I didn’t know you could do that with javascript.

  4. stratosg says:

    well my friend this is java not javascript, and a fairly new technology that oracle develops ADF ;)

  5. elijah says:

    To use bindings from javascript, just do it with EL expressions. Notice, that the javascript code gets evaluated during the rendering phase of lifecycle though.

  6. frank.w says:

    thanks man, that helps!

  7. Amit says:

    Hey there, Many thanks. I was looking for the exact same thing. Apart from accessing the bindings , is it possible to execute bindings actions also from backing bean code. I have been trying it for some time now.
    Please help.

    Thanks.

  8. [...] is a follow up to the original post about acquiring a bindings object in backing beans in ADF. Some have had the question, how to use [...]

  9. Ronal says:

    very good

Leave a Reply