Thursday, April 28, 2011

ViewObjectImpl findByKey(Key key, int i) example

This is a small sample application demonstrating the findByKey(Key key,int i) method.
According to the API:

This can be useful when we want to navigate to a page for instance displaying a given row and not actually filtering the dataset retrieved from the query.

The test case is fairly simple. Lets use the HR schema.
We create an Application and produced the Business Components of the Employees and EmployessDetailsView tables. Just using the JDeveloper Wizard.
The result is to have, among others, the following views:


The findByKey method as we saw in the API accepts a parameter of type Key.
The case for this example is to use the key for one VO object and call the findByKey method to find a row in the other VO and make it current.
So we have to alter the EmpDetailsView entity Object a bit. We need to set the primary to point to EmployeeId and remove the RowId, smartly, produced by JDeveloper wizard.

and the View Object should be like the following:

Note here that we are not creating any ViewLinks. This will simply filter our data and we wont be able to see all other data.
Furthermore, we will create two separate pages for each VO and we will navigate from one page to another.
We will create a form in each page with navigation buttons. Additionally we will move from one page to another and see the appropriate information. 
For example, while in page of Employees, we will navigate to record with EmployeeId=107 and then press the button to go to EmpDetails. The same operation will be done from EmpDetails to Employees.
The goal is to have consistent data according the employeeId.

As you understood by now, we will use the findByKey method...
Simply, we will create two separate methods in the Application Module Implementation class that will do the work.

What we do here is to get the Key from the One's VO current Row and find by key to another.

Now, we need to call these methods. 
We will expose them in the client interface of the Application Module

Next we will create a task Flow of three (3) pages.
Index: from which we will navigate to Employees or EmpDetails pages
Emps: from which we will navigate either to EmpDetails or  Index pages
EmpDetails: from which we will navigate to either Emps or Index pages.

The trick here is to interfere the calls from Emps to EmpDetails and vice versa in order to call the findByKey methods.

Since we have them exposed, we will simply drag and drop them to our taskFlow and have to be called before going to the page we want.


And that is about it..
Every time we navigate from one page to another, the corresponding findByKey will be called and we will see the data set according the EmployeeId.


  1. Thank you for the example. Just one quick question, Dimitrios: I can view the page index and emps separately and emps shows the data in the database correctly, but when I clicked on the "Employees" button in the index page, it did not take me to the emps page. Do you know why?

  2. Run the bounded Task Flow instead of the page itself.

  3. Thank you.Now the pages run fine on the Integrated Application Server inside JDeveloper. But when I deploy the application to an external server, I still can only access the index or emps page separately, but not through the button-click. The same happened even after I changed the database connection type to using a data source. Would you please help again?



Related Posts Plugin for WordPress, Blogger...