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.
hey this is eli’s post! welcome back man 😉 can’t wait for more of your posts!
welcome man 😀
I mean welcome back man
Nice post I didn’t know you could do that with javascript.
well my friend this is java not javascript, and a fairly new technology that oracle develops ADF 😉
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.
thanks man, that helps!
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.
check out this post http://www.stratos.me/2009/12/how-to-use-bindings-in-the-backing-beans-in-adf-10g/
very good
I know this is sort of old, but for the record, oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding is an ADF internal library and should not be used, as this guy found out.
https://forums.oracle.com/forums/thread.jspa?threadID=2255838