You are on page 1of 8

DEVELOPMENT WITH ORACLE JDEVELOPER/ADF 11G REUSING 10G BEST PRACTICES

Andrejus Baranovskis, Vgo Software

Oracle JDeveloper 11g is designed to make enterprise Java development more efficient and to allow developers be more productive. High productivity level can be achieved by using visual and declarative approach that is supported in JDeveloper 11g even on higher level comparing to previous JDeveloper releases. If you are looking for something more and further development simplification is needed, required efficiency level will be provided by the Oracle Application Development Framework (Oracle ADF) an enterprise Java development framework that implements design patterns and eliminates routine coding. JDeveloper provides menu options, wizards, dialogs and property windows related to Oracle ADF development and allow real declarative development based on design patterns implemented by Oracle ADF. Enterprise developer does not need to download any third-party extensions for successful development with JDeveloper, everything is provided out of the box. However, even if developer will miss some functionality, he can develop his own extension for JDeveloper. JDeveloper offers an extension SDK that developer can use to add desired functionality to JDeveloper. Developers familiar with JDeveloper 10g will find many new features in new release, however developers can reuse their best practices acquired during work with 10g. Goal of this paper is to show main steps applied during enterprise applications development with Oracle JDeveloper 11g based on Oracle ADF framework with ADF Business Components in Model layer and JSF in View-Controller layer.

Preparation
Download and install Oracle JDeveloper 11g from OTN: ? Go to http://www.oracle.com/technology/products/jdev/11/index.html download and after unzip, installation is done.

Download and install Oracle Database 10g Express Edition from OTN: ? Go to http://www.oracle.com/technology/products/database/xe/index.html from here you can download and install Oracle XE Database on your server or personal computer. When Oracle XE Database will be installed, unlock HR schema. You can unlock it from Database Home Page, go to Administration section and select Manage Users, you will see HR user schema displayed.

Part 1 Model development


ADF Business Components with Wizards One of the easiest ways to generate Model layer with Oracle ADF framework is to use ADF Business Components creation wizards. ADF Business Components are based on three elements Entity objects, View objects and Application Modules. Entity object represent datasource table row, associations can be created to describe relationships between different Entity objects. View object is a component that contains SQL query and provides mechanism to work with query results. Application Module represents data model available in Model layer and acts as interface to ViewController layer. It is recommended to separate different type components into different packages, this will simplify development and will make project structure more usable. In Figure 1 there is one root package and two sub-packages for Entity and View objects.

www.odtug.com

ODTUG Kaleidoscope 2008

Development with Oracle JDeveloper/ADF 11g Reusing

Baranovskis

Figure 1. Oracle ADF Business Components

List-Of-Values Components JDeveloper provides standard support for List-Of-Values (LOV) components development. LOV component is defined directly in Model layer, for View object attribute. It is easily possible to develop complex LOV components with data dependency. For example, if source defined for LOV component contains complex query logic with Bind variables, its possible to refer through defined variables to data available in current row.

(Employees.DEPARTMENT_ID = :CurrentDept OR Employees.MANAGER_ID IS NULL) AND Employees.EMPLOYEE_ID NOT IN (SELECT Employees1.EMPLOYEE_ID FROM EMPLOYEES Employees1 WHERE Employees1.MANAGER_ID = :CurrentEmp) AND Employees.EMPLOYEE_ID ! = :CurrentEmp

Figure 2. Bind Parameter Values for LOV Component

Calculated Attributes With Groovy expressions in JDeveloper 11g it became possible to develop calculated attributes declaratively. Its enough to open Edit Attribute wizard and provide needed expression for Value field.

www.odtug.com

ODTUG Kaleidoscope 2008

Development with Oracle JDeveloper/ADF 11g Reusing

Baranovskis

Figure 3. Calculated Attribute Based on Groovy Expression


Example of expression written with Groovy language

((Salary == null) ? 0 : Salary) - (((Salary == null) ? 0 : Salary) * 25) / 100

Dependent Validation Rules Validation logic can be implemented with validation rules directly on Entity objects in Model layer.

Figure 4. Entity Validation Rules


JDeveloper 11g provides different types of rules that can be used to implement validation logic: Collection, Compare, Script Expression Example, Key Exists, Length, List, Method, Range, Regular Expression and Unique Key. Example of validation expression written with Groovy language:

if((MinSalary * 100) / MaxSalary < 75) { return false; } return true;

www.odtug.com

ODTUG Kaleidoscope 2008

Development with Oracle JDeveloper/ADF 11g Reusing

Baranovskis

Part 2 ViewController development


Page Templates in JDeveloper 11g Very powerful feature introduced with JDeveloper 11g is Page Templates development. With Page Template it is possible to design actual page layout structure and reuse this structure in different pages. If there will be need to change designed layout, it is enough to change it once in Page Template, applied changes will be reflected for pages automatically.

Figure 5. Page Template Structure


However, Page Templates are not only about design, data bound components are supported as well. Developer can put data bound table into Page Template in order to reuse it in pages.

Page Fragments and Regions Page Fragments and Regions allow to develop more dynamic applications with reusable components. If there is functionality in your application that is reused in several pages, you can put it into page fragment and reuse it. This will allow to develop reusable functionality only once. Page Fragments are not just independent parts of application, each Page Fragment can accept and return parameters. What is most important, when input parameter changes, Page Fragment can be automatically refreshed in order to reflect changes.

Figure 6. Task Flow Input Parameter Definition

www.odtug.com

ODTUG Kaleidoscope 2008

Development with Oracle JDeveloper/ADF 11g Reusing

Baranovskis

Figure 7. Task Flow Input Page Parameter Definition


Page Fragments are reused as Regions in JSF pages through ADF Task Flows. Example of ADF Task Flow definition in page definition file:

<taskFlow id="taskflowemployeesdefinition1" taskFlowId="/WEB-INF/task-flow-employees-definition.xml#task-flow-employees-definition" xmlns="http://xmlns.oracle.com/adf/controller/binding" Refresh="ifNeeded"> <parameters> <parameter id="JobIdParam" value="#{bindings.jobIdVar_Attr.inputValue}" xmlns="http://xmlns.oracle.com/adfm/uimodel"/> </parameters> </taskFlow>

ADF Task Flows ADF Task Flow in JDeveloper 11g is a new feature that improves JSF page flow available in previous JDeveloper releases. With ADF Task Flow large navigation flow in application can be splitted into several smaller reusable modules. ADF Task Flow are much more than navigation transactions can be managed just directly within navigation modules. Exist possibility to call remote ADF Task Flows available in separate application, this allows to implement reusability on application level.

Figure 8. Conditional Navigation

www.odtug.com

ODTUG Kaleidoscope 2008

Development with Oracle JDeveloper/ADF 11g Reusing

Baranovskis

ADF Faces Rich Client Oracle ADF Faces Rich Client provides standard set of JSF components with built -in Ajax functionality. With ADF Faces Rich Client its easy to use declarative development approach. Developer can drag and drop data bound components from component palette and generate menus, dialogs, tabs, accordions, dividers, forms and sortable tables. Such components as geographic maps, dynamic charts and graphs can be declaratively created with ADF Faces Rich Client as well. In Figure 9 you can see example of screen that contains ADF Faces Rich Client components.

Figure 9. Oracle ADF Faces Rich Client

Part 3 Service Oriented Architecture (SOA) development


ESB Flow to Write into File JDeveloper 11g offers tools to develop complete SOA application. Integration developer can integrate separate applications using Web Services functionality. In Figure 10 you can find sample ESB Flow designed to write information into File System. This flow contains three parts Exposed Web Service available to external clients, Mediator to wire Exposed Web Service with File Adaptor, and File Adaptor to write information obtained from Web Service to File System. In the next section it is described how to call ESB Flow from application developed with Oracle ADF.

www.odtug.com

ODTUG Kaleidoscope 2008

Development with Oracle JDeveloper/ADF 11g Reusing

Baranovskis

Figure 10. ESB Flow

Web Service Invocation from ADF Application JDeveloper 11g allows to have Data Controls based on various sources ADF Business Components, EJB, Web Service, XML files, etc. In order to call Web Service, developer needs to create Data Control based on this Web Service. It can be done with JDeveloper 11g wizards. When Data Control structure is created, developer can operate with available actions in the same way as it is done with Data Control based on ADF Business Components.

<methodAction id=execute InstanceName=JobsArchive DataControl=JobsArchive RequiresUpdateModel=true Action=invokeMethod MethodName=execute IsViewObjectMethod=false> <NamedData NDName=JobID NDValue=${bindings.JobId.inputValue} NDType=java.lang.String/> <NamedData NDName=JobTitle NDValue=${bindings.JobTitle.inputValue} NDType=java.lang.String/> <NamedData NDName=MinSalary NDValue=${bindings.MinSalary.inputValue} NDType=java.math.BigDecimal/> <NamedData NDName=MaxSalary NDValue=${bindings.MaxSalary.inputValue} NDType=java.math.BigDecimal/> </methodAction>

Finally, when action to invoke Web Service is defined in Page Definition file, this action can be invoked Backing Bean method associated with command button. Below is listed code source needed to invoke action associated with Web Service.

Public String saveButton_action() { BindingContainer bindings = getBindings(); OperationBinding operationBinding = bindings.getOperationBinding(execute); operationBinding.execute(); operationBinding = bindings.getOperationBinding(Commit); Object result = operationBinding.execute(); if (!operationBinding.getErrors().isEmpty()) { return null; } return save; }

www.odtug.com

ODTUG Kaleidoscope 2008

Development with Oracle JDeveloper/ADF 11g Reusing

Baranovskis

Resources
1. 2. Oracle Technology Network (OTN) http://www.oracle.com/technology/index.html Andrejus Baranovskiss Blog http://andrejusb.blogspot.com

www.odtug.com

ODTUG Kaleidoscope 2008

You might also like