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

3 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
  3. Hi,

    I got an error in oper.execute() , which is a valid error as per the validations written in backend.
    I wanted to clear the errors by clearing the errors list.

    oper.getErrors().clear();

    But even if I clear the list, the list is not getting cleared.

    Is there some way to clear this?

    Thanks,
    Nigel.

    ReplyDelete

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...