Sunday, April 3, 2016

Using java class as a instance in method action binding - Part 1

Hi All,

Today i will be explaining one interesting use case where we can call java class method via ADF binding layer without creating manually data control.

This is very useful if you are using contextual event where when you consume contextual event you should have some method via binding layer to handle it.

In normal case when we call any method from application code the below code generated by jdeveloper in page def file.

 <methodAction id="moduleMethod" RequiresUpdateModel="true" Action="invokeMethod"   MethodName="moduleMethod"
                      IsViewObjectMethod="false" DataControl="AppModuleDataControl"

and below code to call method in backing bean.

    public void realButtonClick(ActionEvent actionEvent) {
        BindingContainer bindingContainer = JavaUtil.getBindingContainer();
        OperationBinding binding = bindingContainer.getOperationBinding("moduleMethod");

But suppose you want to call any method which is present in java class and you want to call the same way we did for actual am method. Below is code in method action binding , page def code.

 <methodAction id="callingFakeMethod" Action="invokeMethod" MethodName="helloFake" IsViewObjectMethod="false"
                      DataControl="AppModuleDataControl" InstanceName="FakeRb"></methodAction>

and below code is to call method in backing bean.

    public void fakeButtonClick(ActionEvent actionEvent) {
        BindingContainer bindingContainer = JavaUtil.getBindingContainer();
        OperationBinding binding = bindingContainer.getOperationBinding("callingFakeMethod");

Let us understand this , the value of instance name is FakeRb. Basically i have create the class name this and added this class inside adfc-config.xml file with none scope.

The point to note here that the scope should be JSF scope not ADF scope. You can use request, view , session , application or none scope. It will not work if you use backing bean , page flow scope. It will throw exception.


If you see i have not used any expression  language. I have observed that it is working without using el. However we can also use el but that should be Immediate evaluation expressions($) not deferred evaluation expressions (#). The below code will also work.


And please do not prefix with and scope name. And below is link to find source code.


No comments:

Post a Comment