Wednesday, July 23, 2008

Executing multiple actions upon a single user interaction in Oracle ADF

A classic use of MVC architecture I must say. You have a button (Delete), and you want to remove the record from view's cache and also post the changes by committing to the database.
In otherwords, #{bindings.Delete.execute} would delete the row just from the cache. We need to explicitly commit the changes to the database henceforth.
We have dragged and dropped a Delete action as a command button. When the user clicks on this, the selected row is just removed from the cache. In order to commit the changes, we need to somehow call #{bindings.Commit.execute} action.
How do we do both these actions (Delete and Commit) on just one user click of the button ?
For the af:commandButton, define an actionListener="#{backing_Delete.deleteEmployee}"
In your backing bean 'backing_Delete', your deleteEmployee method looks like this:
public void deleteEmployee{
try{
ADFUtils.executeOperation("pageDef","Delete");
ADFUtils.executeOperation("pageDef","Commit");
}
catch(Exception ex){
throw new RuntimeException (ex);
}
}
Make sure that, you have defined these operations(Delete and Commit) in your pageDef.

This way, from one user interaction (click on the Delete button), from the view layer, you are coming through the controller (backing bean) and executing two operations on the model. Naturally, controller should be able to perform more than one operation on the model.
Done !

No comments: