Friday, February 5, 2010

JDeveloper, and Weblogic:Accessing Detailed Views from Master One Using Java

One of the most addressable issues in Oracle ADF Application Development is how to access your business model components through Java method call. Accessing the parent view that requires a bind variable and attaching it to a page doesn't mean that the details views related to master one at data model level will execute with same bind variable.

In this post we will address the problem of how to call a master view with bind variable set through Java call ? and at the same time to fetish data from detail views ?

First of all make sure that your data model is built to reflect master detail relation. A view link between Master and Detail should be created at first and added to Data Model, like simple two key join in a select statement:

As you note a country-City relation ship exists, in which you must get country to get its cities.
The country view has a bind variable set at run-time through expression language and called through execute with params method call. This what happened at normal page flow navigation. But, in our case we want to set the bind variable using Java code and then looping thourgh to get the detailed cities.



1- need to create a Java class that access your Application Model like this:


String amDef = "model.AppModule";
String config = "AppModuleLocal";
ApplicationModule am =
Configuration.createRootApplicationModule(amDef, config);

2- Access CountryView1 view, set the bind variable value, execute the query and then get the first record assuming the country code is a primary key:


ViewObject counrty = am.findViewObject("CountryView1");

counrty.setNamedWhereClauseParam("country_code", "2");


/* Country Code is a Primary key so it should return only one record so
no need to loop through records, just get the first record*/

counrty.executeQuery();


counrty.first();



3- In this step you will get the details row set and then navigate through to get the desired detail view, in our case there is only one detail view, but the if condition exists for future enhancements.


RowSet rowset1[] = counrty.getDetailRowSets();


for (int rs = 0; rs <rowset1.length; rs++)

if (rowset1[rs].getName().equals("CityView1")) {

// Name of the detail view is CityView1


RowSet cities = rowset1[rs];
cities.executeQuery();


while (cities.hasNext()) {


/* Do what ever you want on data found,
i.e fill it with Page flow scope variable for later manipulation

on another page */


}

}

}


4- The full code should be like this, a method call can be added to task flow navigation to call the method get_cities for later data handling or decision on data retrieved from call.

package view;



import oracle.jbo.ApplicationModule;
import oracle.jbo.RowSet;

import oracle.jbo.ViewObject;

import oracle.jbo.client.Configuration;



public class TestClass {

public TestClass() {

super();

}



public void fill_Cities() {


String amDef = "model.AppModule";
String config = "AppModuleLocal";

ApplicationModule am =

Configuration.createRootApplicationModule(amDef, config);


ViewObject counrty = am.findViewObject("CountryView1");



counrty.setNamedWhereClauseParam("country_code", "2");
counrty.executeQuery();

counrty.first();



RowSet rowset1[] = counrty.getDetailRowSets();
for (int rs = 0; rs <>
if (rowset1[rs].getName().equals("CityView1")) {
RowSet cities = rowset1[rs];

cities.executeQuery();



while (cities.hasNext()) {

//Place your code here

}


}

}
}


}






No comments:

Post a Comment