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
Recommended Post Slide Out For Blogger