Thursday, October 16, 2008

Form Opening in Find Mode

It can be that topic for current blog post looks very basic, however I will describe one simple thing that can make your development life easier. I will explain how to use Method Call in ADF Task Flow in order to open called form in Find mode, without using invokeAction in Page Definition.

How often you develop forms, where one of key requirements is to open form in Find mode. From my experience, it is quite common behavior. However, usually it is not enough just to define invokeAction in Page Definition and execute Find action each time when page is opened (postback == false). For example, form can be opened in Find mode from main menu, but it should be opened in Edit mode, when is called from separate specific form. In such case, JDeveloper/ADF 10.1.3 developer will create parameters and evaluate through expression language in invokeAction. This approach works, however as always there is a better approach.

This better approach is to use ADF Task Flow functionality available in JDeveloper/ADF 11g. In ADF Task Flow its possible to define Method Calls and separate action logic with page logic. Please, read ADF Developer Guide 11g, in order to get more information about ADF Task Flows.

You can download sample application I have developed - FindMethod.zip. This application is based on standard HR schema from Oracle and implements two pages - index.jspx and main.jspx. First page is defined in unbounded ADF Task Flow and calls second page from bounded ADF Task Flow. Second page is opening in Find mode automatically, without invokeAction in Page Definition.

Main logic, related to this post, is in bounded ADF Task Flow task-flow-definition.xml file:


You can see that as default activity is selected Find Method Call. Idea is - when bounded ADF Task Flow will be opened, default Find activity will trigger and will set iterator to Find mode. Sounds simple, however in practice is little bit more complex. If you will just drag and drop Find action from Data Control and define it as a default activity, it will not work - separate Page Definition file for Method Call will be generated, and Find action will be invoked not for iterator available in main.jpx Page Definition file, but for iterator available in Page Definition associated with Method Call - means Form will not be opened in Find mode.

Second idea that can come to your mind is simply to associate Method Call activity with Find action available in main.jspx Page Definition file:


But, this also will not work, exception on runtime - Page Definition not found:


And now, its time to describe a solution. You need to open DataBindings.cpx file and to assign same Page Definition file to Method Call created in ADF Task Flow as is assigned to a page. In our case, there will be two Page Mappings (one is real, second is for Method Call) and one Page Definition Usage:


When assignment will be done, go back to bounded ADF Task Flow and provide Find action for Method Call from Page Definition file associated with a main.jspx page:


Now it looks everything is done and we can run application, in index.jspx page lets press Find button and open bounded ADF Task Flow with default Find action:


Form is opened in Find mode without any invokeAction declaration:


Just to summarize, ADF Task Flow functionality - Method Call, in this case allows to put form to Find mode automatically when bounded ADF Task Flow is opened. All the other pages inside bounded ADF Task Flow can open the same form without invoking Method Call, what gives higher flexibility.

No comments: