30 July, 2012

ADF : Call Method from PageDefinition Programatically

I will explain how to call  a method in Managed Bean from PageDefinition using Java code.

1- Create methodAction binding in PageDefinition for a method

You can add  methodAction  binding in PageDefinition for a methods exists in ViewObjects or Application Modules at Data Control


Open PageDefinition and add new action 







From the next dialogue choose a method from DataControl


2- You can use the below code for calling the previous method

    public void callMethodFromPageDefinition() {
        BindingContext bCtx = BindingContext.getCurrent();
        DCBindingContainer DcCon = (DCBindingContainer)bCtx.getCurrentBindingsEntry();

        // Note "initEmpView" is the Id of actionMethod binding in PageDefinition
        OperationBinding oper = DcCon.getOperationBinding("initEmpView");

        //If a method has a parameters you can pass it through the below method
        oper.getParamsMap().put("Param1Name", "Param1Value");
        oper.getParamsMap().put("Param2Name", "Param2Value");

        //Execute a method
        oper.execute();

        //Check for error after executing the method
        if (oper.getErrors().size() > 0) {
            //It has errors
            //Handle an errors here
        }
    }


Thanks

2 comments:

  1. It would be very nice of you if you recommend other resources concerning this subject just in case you happen to know any.

    ReplyDelete
  2. I need call two PageDef from a single ManagedBean, this bean, is from two pages similar, but with some components differents, this bean must to save the data from the two pages, but with parameters differents.
    how i can access to two differents binding, i try with
    " BindingContext bCtx = BindingContext.getCurrent();
    DCBindingContainer DcCon = (DCBindingContainer)bCtx.getCurrentBindingsEntry();"
    but, only get with the current binding, but not with the others bindings, how i can acces from the same bean to others bindings?
    something as BindingContext bCtx = BindingContext.setCurrent(.....);

    ReplyDelete

How to Pass Parameters to ActionListener in ADF

In some cases, it is required to pass a value to ActionListener of ADF Button. The method that can be invoked by actionListeners has only...