Sunday, September 5, 2010

ADF 11g methodAction and invokeAction in the pageDef


Here is a small example focusing on how to create a methodAction and an invokeAction in a pageDef. Those properties in a pageDef can be very helpful especially when we want to do things more declaratively or have automated actions for your page.

Download The Sample Application.

What we are going to do here is a slight difference of a previous post.
In the previous post we entered a page in insert mode.

Now, we are not going to use the feature of methodCall.
We are going to have the logic in our pageDef.
We are going to use the methodAction and the invokeAction.

First, we create the model, for this example we are going to use the HR schema in the ORACLE XE.

We create BC(entities and views) for employees table.

We generate the Application module as well.

We create the method in the application Module as in the previous post here 

We create the java class for our Applciation Module (AM).

We create the java classes for Employees View the same as we did for the AM.

In the java class of the AM we create the method that creates and inserts a new row in the Employees View.

We will now expose the method in the client interface of the AM

with result:

After exposing the Method from AM, we will create a methodAction pointing to method exposed.

NOTE: we have to create a jspx page  with a pageDef. To create a pageDef simply drag a drop on the jspx or right click on the jspx and select create page Definition.

1) Open the pageDef of the jspx.  and in the Bindings Column add a new binding of type methodAction

On the second screen:

With the result:

Now, this methodAction can be called as any other operation in the bindings.

In our case, we want to call this method every time we enter the jspx.

In the previous post, we did it with a separate methodCall.
In this case we will create an InvokeAction tha calls this methodAction

In our pageDef again, we will create an invokeAction.

After ok is pressed:

The result to this is:

We are not just done yet.

We need to set when this invokeAction will be invoked.
We go on the property Inspector of this executable and change the refresh condition
to prepareModel:

At this point we have created an invokeAction that binds a methodAction and it will be invoked everytime the prepareModel is invoked.

For more details on the refresh property, please refer to the documentation:

The last thing to do is to drop the Employees form into the page.

On the wizard window check the navigation buttons check Box.
As a final, also drag an drop the Commit operation onto the jspx.

Thats about it.

When we run the page:

Download the sample Application.


  1. Hi Dimitrios,

    I am new to ADF and I tried to do exactly the same way you have posted but when I enter some data and click on commit button I get this error "Entity XXXEO cannot be posted to the database because it has no attributes set" on my page.

    Your help is greatly appreciated.

  2. Hi Anonymous...

    Well the first thing that comes in mind is that there is a problem in your entity object. Double check that your View Object is working ok on your Application Module. If it is not, check the EO in detail. Also, if you have generated any java classes of that EO, check if the java code is correct. Sometimes it might produce wrong code, especially if you do some changes to your EO. Finally, check you EO xml code and see if everything is in place as expected.



  3. Hi Dimitris,

    Thank you for your quick response. I did check the View Object in AM and its working fine. I am able to save and delete data from AM. I don't have any java classes for the EO and everything looks in place for it. I am using Jdev version

    Your help is greatly appreciated.

  4. Hi anonymous.

    If you can, send me on my profile's email the project with the problem.
    Also it would be great if you could upgrade your JDev to the latest version.



  5. While running your sample code , getting the following error even though I have provided values for all the attributes

    Attribute LastName in AppModule.EmployeesView1 is required.
    Attribute Email in AppModule.EmployeesView1 is required.
    Attribute HireDate in AppModule.EmployeesView1 is required.
    Attribute JobId in AppModule.EmployeesView1 is required

    Any idea how to fix this ?I am using jDev


  6. Hi Dimitris
    I am facing the same problem as anonymus above where I get Attribute is required.Have you found an answer to this? thanks in advance.

  7. Hi EJ and Anonymous.
    Sorry for the delayed response.
    This is just an example of how to invoke an Action that points to a method Action. If you place some logging in the method from the Application module you will see that the method is called twice and that is why the exceptions are thrown. Change the refresh property of the invokeAction From prepareModel to renderModelIfNeeded. With this change the commit operation will work and the invokeAction will be called again because it will be needed. Again, the point of the example is to call the invokeAction but for the commit button, as it is obvious, the prepareModel valuewas not enough. The value renderModuleIfNeeded completes the commit operation.



Related Posts Plugin for WordPress, Blogger...