How to invoke model layer methods from managed bean (Best Practice to write business logic in ADF)

Sharing is Caring

Again a post about ADF Basics (invoke model layer methods) for those who are starting with ADF
This topic is posted multiple times and one of the most asked questions on OTN

How to access AM method in bean?
How to pass parameters to model from managed bean (viewController)?
How to pass taskFlow parameter to model?

Or sometimes I have to tell the user that you should not access ApplicationModule or not update model from the managed bean and then I post a link about this
I often post a link of Frank’s blog
Best practice invoking business services methods from JSF beans
It is well explained but still user not able to do because he/she doesn’t know about clientInterface, pageDef etc

So i thought to write a step by step implementation of this and if you want to know why it is best to call the method through binding layer?
Then please refer Frank’s blog 🙂

What I am going to explain is How to call a method defined in ApplicationModule Impl class in managed bean ?
So for this first, I need to define a method in ApplicationModule Impl class

Here I am using Departments table of HR Schema and I have created a method to create a new row in Departments viewObject
See the implementation part –

    • To create AMImpl class–> Open ApplicationModule in editor–> Goto Java tab–> Click on edit (pencil) icon and check the checkbox to generate class



    • Now write your logic and create method here so i have created a method to create department record and this method takes a parameter i;e DepartmentId

     *Custom Method to create row in departments viewObject
    public void createDepartmentRecord(Integer deptId) {
        ViewObject deptVo = this.getDepartmentsVO1();
        Row newRow=deptVo.createRow();
        newRow.setAttribute("DepartmentId", deptId);


    • Next step is to add this method to client interface so that we can access this, Again open AM in editor –>Go to Java tab–> Click on edit icon of clientInterface–> Shuttle method to selected side



    • Now to add this method in pageDef, Open page in editor–> Click on Bindings tab (bottom of editor)–> Click on green plus icon of bindings section–> Select methodAction and click on ok



invoke model layer methods

Now select method name here and click ok

Now you can see this method is added in pageDef


    • Now time to call this method in managed bean so for that added a button in the page and created actionListener in bean. See the code

 /**Method to get Binding Container of page
  * @return
 public BindingContainer getBindings(){
     return BindingContext.getCurrent().getCurrentBindingsEntry();

/**Calling method defined in AMImpl class to create new Department
 * @param actionEvent
public void callAMMethodToCreateDepartmentAction(ActionEvent actionEvent) {
//Get OperationBinding of method
OperationBinding ob=getBindings().getOperationBinding("createDepartmentRecord");
//Passing parameter to method -Get parameter map and use paramater name as key
ob.getParamsMap().put("deptId", 9999);
//Execute this method
//Check for errors
// Successfully Executed


  • Now run the application and check, is it working? 😉

On click, a new row is inserted in the table with DepartmentId 9999

All done 🙂
In the same way, you can call method defined in any model implementation class, remember don’t access ApplicationModule or viewObject directly, make use binding layer
and again why it is best practice ?? to know this read Frank’s blog 🙂
Cheers 🙂 Happy Learning

Related Posts

0 thoughts on “How to invoke model layer methods from managed bean (Best Practice to write business logic in ADF)”

  1. thank for this post

    its possible to to explain how we can invoke method that return rowset and in managed bean and iterate through this and return the value in tabular

  2. I've tried this, even had it working at sometime, but I changed the method and now it doensn't work. keeps giving me the error:

    XXX being the name of my connection.
    What troubles me is that if I run the AM it works fine.

  3. Because of the tags on ADF errors the error doesn't show it was like this

    <Warning> <oracle.adf.share.jndi.ReferenceStoreHelper> <BEA-000000> <Incomplete connection reference object for connection:XXX>

  4. Hello Ashish. Could you help me with following problem in ADF 12?
    I have AM1 (which "connect" to database1) and AM2 (which "connect" to database2).
    AM1 have VO1
    AM2 have VO2

    I want to create one custom ADF BC Method which doing following:
    1) set bind_var for VO1, execute VO1
    2) result of VO1 map to bind_var VO2, execute VO2

    How can I do this?

  5. I'm kind of new in ADF and I may be wrong but the way I'd do it would be having two methods calling each other, something like this:

    import AM2_impl;

    … do stuff …
    return AM2_impl.meth2(pojo_holding_data);


    meth2(pojo data_from_AM1){
    … do stuff …

    this is just a general concept, but I hope it helps

  6. Hi Ashish, I follow all your blogs. It really helps me to develop screens. I have been working on ADF for sometime. I keep wondering, Where are you getting the class and methods information to customize any functionality in ADF(Eg:BindingContext.getCurrent().getCurrentBindingsEntry() to call binding related methods). Is this documented anywhere. Because I have gone through couple of ADF tutorials. I could not find anywhere.

Leave a Reply

Your email address will not be published. Required fields are marked *