This chapter describes the architecture and key functionality of Oracle Application Development Framework (Oracle ADF) when used to build a Fusion web application that uses ADF Business Components, ADF Model, ADF Controller, and ADF Faces, in other words, the full Fusion technology stack. It also provides high-level development practices.
This chapter includes the following sections:
For definitions of unfamiliar terms found in this and other books, see the Glossary.
The Oracle Application Development Framework (Oracle ADF) is an end-to-end application framework that builds on Java Platform, Enterprise Edition (Java EE) standards and open-source technologies. You can use Oracle ADF to implement enterprise solutions that search, display, create, modify, and validate data using web, wireless, desktop, or web services interfaces. Because of its declarative nature, Oracle ADF simplifies and accelerates development by allowing users to focus on the logic of application creation rather than coding details. Used in tandem, Oracle JDeveloper and Oracle ADF give you an environment that covers the full development lifecycle from design to deployment, with drag and drop data binding, visual UI design, and team development features built in.
You can also develop ADF applications using Oracle Enterprise Pack for Eclipse (OEPE). OEPE is a set of plug-ins designed for the Eclipse IDE to support Java EE development. OEPE also includes support for ADF application development, though that support is more limited than that provided by JDeveloper. For more information, see http://www.oracle.com/technetwork/developer-tools/eclipse/overview/index.html .
You can develop Fusion web applications, which are applications built with the full Fusion technology stack—ADF Business Components, ADF Model, ADF Controller, and JavaServer Faces pages with ADF Faces components. As a companion to this guide, you can download and view the Summit sample applications for Oracle ADF, which help to illustrate the concepts and procedures in this guide (and other Oracle Fusion Middleware developer guides). The examples in this sample application are built using the Fusion web application technology stack. Screenshots and code samples from this application are used throughout this guide to provide you with real-world examples of using the Oracle ADF technologies. For more information about downloading and using the Summit ADF sample applications, see Chapter 2, "Introduction to the ADF Sample Application."
In line with community best practices, applications you build using the Fusion web technology stack achieve a clean separation of business logic, page navigation, and user interface by adhering to a model-view-controller architecture. As shown in Figure 1-1, in an MVC architecture:
Figure 1-1 MVC Architecture Cleanly Separates UI, Business Logic and Page Navigation
Figure 1-2 illustrates where each ADF module fits in the Fusion web application architecture. The core module in the framework is ADF Model, a data binding facility. ADF Model enables a unified approach to bind any user interface to any business service, without the need to write code. The other modules that make up a Fusion web application technology stack are:
In addition to ADF Faces, Oracle ADF also supports using the Java and standard JSF view technologies. For more information about these technologies, see Developing Applications with Oracle JDeveloper . Oracle ADF also provides support for using Microsoft Excel as a view layer for your application. For more information, see Developing Applications with Oracle ADF Desktop Integration .
Figure 1-2 Simple Oracle ADF Architecture
For more information about the Oracle ADF architecture and the individual ADF technologies, see Understanding Oracle Application Development Framework .
Oracle ADF emphasizes the use of the declarative programming paradigm throughout the development process to allow users to focus on the logic of application creation without having to get into implementation details. Using JDeveloper with Oracle ADF, you benefit from a high-productivity environment that automatically manages your application's declarative metadata for data access, validation, page control and navigation, user interface design, and data binding.
At a high level, the development process for a Fusion web application usually involves the following:
The first step in building a new application is to assign it a name and to specify the directory where its source files will be saved. When you create an application using the application templates provided by JDeveloper, it organizes your workspace into projects and creates and organizes many of the configuration files required by the type of application you are creating.
One of these templates is the ADF Fusion Web Application template, which provides the correctly configured set of projects you need to create a web application that uses ADF Faces for the view, ADF Controller for the page flow, and ADF Business Components for business services. When you create an application workspace using this template, JDeveloper automatically creates the JSF and ADF configuration files needed for the application.
One part of the application overview is the Fusion Web Application Quick Start Checklist. This checklist provides you with the basic steps for creating a Fusion web application. Included are links to pertinent documentation, prerequisites, and the ability to keep track of status for each step in the checklist, as shown in Figure 1-3.
Figure 1-3 Fusion Web Application Quick Start Checklist
JDeveloper also creates a project named Model that will contain all the source files related to the business services in your application, and a project named ViewController that will contain all the source files for your ADF Faces view layer and model layer, including files for the controller.
To save you having to add the associated libraries yourself, JDeveloper automatically adds the following libraries to the data model project, once you create a business component:
JDeveloper also adds the following libraries to the view project:
Once you add a JSF page, JDeveloper adds the Oracle JEWT library.
You can then use JDeveloper to create additional projects, and add the packages and files needed for your application.
If you plan to reuse artifacts in your application (for example, task flows), then you should follow the naming guidelines presented in Chapter 44, "Reusing Application Components" in order to prevent naming conflicts.
You can edit the default values used in application templates, as well as create your own templates. To do so, choose Application > Manage Templates .
Figure 1-4 shows the different projects, packages, directories, and files for the Summit ADF sample application, as displayed in the Applications window.
Figure 1-4 Summit ADF Sample Application Projects, Packages, and Directories
For more information, see the "Managing Applications and Projects" section of Developing Applications with Oracle JDeveloper .
When you work with your files, you use mostly the Applications window, editor window, the Structure window, and the Properties window, as shown in Figure 1-5. The editor window allows you to view many of your files in a WYSIWYG environment, or you can view a file in an overview editor where you can declaratively make changes, or you can view the source code for the file. The Structure window shows the structure of the currently selected file. You can select objects in this window and then edit the properties for the selection in the Properties window.
Figure 1-5 The JDeveloper Workspace
In JDeveloper, you can work with a database that is online, or, after you create your application workspace, you can copy database objects from a database schema to an offline database or project where they become available as offline database objects, saved as .xml files. With either an online or offline database, you can then create and edit database object definitions within a project. You can also compare your offline database objects with other offline or live database schemas and generate SQL statements (including CREATE , REPLACE , and ALTER ).
For example, you can drag a table from a database connection that your application defines onto a database diagram and JDeveloper will give you the choice to model the database object live or offline (to create the .xml file representation of the object). Modeling database definitions, such as tables and foreign keys, visually captures the essential information about a schema. You can use the diagram to drag and drop columns and keys to duplicate, move, and create foreign key relationships. Working in offline mode, whenever you model a node on a diagram, JDeveloper creates the underlying offline object and lists it in the Applications window. Working with a live schema, JDeveloper updates the live database object as you amend the diagram. You can create multiple diagrams from the same offline database objects and spread your offline database across multiple projects.
Using a database diagram like the one shown in Figure 1-6 you can visualize the following:
In addition to using the diagram directly to create and edit database objects, you can work with specific database object editors. After you have finished working with the offline database objects, you can generate new and updated database definitions to online database schemas.
When you work with the database diagram you can customize the diagram to change the layout, change how objects are represented and grouped, add diagram annotations to specify dependencies or links (such as URLs), and change visual properties, such as color and font of diagram elements.
Figure 1-6 Database Diagram for Payments Grouping
For more information about modeling database definitions with database diagrams, see the "Creating, Editing, and Dropping Database Objects" section in Developing Applications with Oracle JDeveloper .
After creating an application workspace, you may decide to begin the development process by doing use case modeling to capture and communicate end-user requirements for the application to be built. Figure 1-7 shows a simple diagram for an HR administrator creating a new employee that you might design using the UML modeler in JDeveloper. Using diagram annotations, you can capture particular requirements about what end users might need to see on the screens that will implement the use case. For example, in this use case, it is noted that the user will choose to create a new employee while viewing a list of all employees.
Figure 1-7 Use Case Diagram for Viewing Order History
For more information about creating use case diagrams, see the "Developing Applications Using Modeling" chapter of Developing Applications with Oracle JDeveloper .
By modeling the use cases, you begin to understand the kinds of user interface pages that will be required to implement end-user requirements. At this point, you can use these diagrams as documentation tools that will help as you begin to design the flow of your application. In a Fusion web application, you use ADF task flows instead of standard JSF navigation flows. Task flows provide a more modular and transaction-aware approach to navigation and application control. Like standard JSF navigation flows, task flows contain mostly viewable pages (or page fragments). Aside from navigation, task flows can also have nonvisual activities that can be chained together to affect the page flow and application behavior. For example, these nonvisual activities can call methods on managed beans, evaluate an EL expression, or call another task flow. This facilitates reuse, as business logic can be invoked independently of the page being displayed.
Figure 1-8 shows a task flow for creating an employee. In this task flow, GeneralInfo and Confirmation are view activities that represent pages, while CreateInsert is a method call activity. When the user enters this flow, the CreateInsert activity is invoked (because it is the entry point for the flow, as denoted by the green circle) and the corresponding method is called. Because this is a call to a method, and the method itself is not included in the task flow, the method can be reused elsewhere in the application. Or, the logic in the method could be changed, without affecting the metadata for the page flow. From there, the flow continues to the GeneralInfo page, and once the data is submitted, to the Confirmation page.
Figure 1-8 Task Flow to Create an Employee
ADF Controller provides a mechanism to define navigation using control flow rules. The control flow rule information, along with other information regarding the flow, is saved in a configuration file. Figure 1-9 shows the Structure window for the task flow. This window shows each of the items configured in the flow, such as the control flow rules. The Properties window (by default, located at the bottom right) allows you to set values for the different elements in the flow.
Figure 1-9 Task Flow Elements in the Structure Window and Properties Window
Aside from pages, task flows can also coordinate page fragments. Page fragments are JSF documents that are rendered as content in other JSF pages. You can create page fragments and the control between them in a bounded task flow as you would create pages, and then insert the entire task flow into another page as a region . Because it is simply another task flow, the region can independently execute methods, evaluate expressions, and display content, while the remaining content on the containing page stays the same.
Regions also facilitate reuse. You can create a task flow as a region, determine the pieces of information required by a task and the pieces of information it might return, define those as parameters and return values of the region, then drop the region on any page in an application. Depending on the value of the parameter, a different view can display.
The chapters in Part I, "Creating ADF Task Flows" contain information about using task flows. For general information about task flows and creating them, see Chapter 20, "Getting Started with ADF Task Flows." For information about task flow activities, see Chapter 21, "Working with Task Flow Activities." If you need to pass parameters into or out of task flows, see Chapter 22, "Using Parameters in Task Flows." For more information about regions, see Chapter 23, "Using Task Flows as Regions." For information about advanced functionality that task flows can provide, such as transactional capabilities and creating mandatory sequences of pages (known as trains ), see Chapter 24, "Creating Complex Task Flows." For information about using task flows to create dialogs, see Chapter 25, "Using Dialogs in Your Application."
When designing the application, you may find that some aspects of your application can be reused throughout the application. For example, you might have one developer that creates the business components, and another that creates the web interface. The business component developer can then save the project and package it as a library. The library can be sent to other developers who can add it to their resource catalog, from which they can drag and drop it onto any page where it's needed. Figure 1-10 shows a resources catalog in the Resources window of JDeveloper.
Figure 1-10 Resources Window in JDeveloper
Be sure to note all the tasks that can possibly become candidates for reuse. Chapter 44, "Reusing Application Components" provides more information about the ADF artifacts that can be packaged and reused as an ADF library, along with procedures both for creating and using the libraries.
Typically, when you implement business logic as ADF Business Components , you do the following:
The chapters contained in Part I, "Building Your Business Services" provide information on creating each of these artifacts. The chapters in Part I, "Completing Your Application" provide additional information, such as extending business objects, tuning, and state management.
Once you have an understanding of the data that will be presented and manipulated in your application, if you haven't already done so, you can build your database (for more information, see the "Designing Databases Within Oracle JDeveloper" chapter of Developing Applications with Oracle JDeveloper ). Once the database tables are in place, you can create a set of entity objects that represents them and simplifies modifying the data they contain. When you use entity objects to encapsulate data access and validation related to the tables, any pages you build today or in the future that work with these tables are consistently validated. Any relationships between the tables will be reflected as associations between the corresponding entity objects.
Once the entity objects are created, you can define control and attribute hints that simplify the display of the entities in the UI, and you can also add behaviors to the objects. For more information, see Chapter 4, "Creating a Business Domain Layer Using Entity Objects."
Once the reusable layer of business objects is created, you can implement the application module's data model and service methods with which a UI client can work.
The application module's data model is composed of instances of the view object components you create that encapsulate the necessary queries. View objects can join, project, filter, sort, and aggregate data into the shape required by the end-user task being represented in the user interface. When the end user needs to update the data, your view objects reference entity objects in your reusable business domain layer. View objects are reusable and can be used in multiple application modules. For more information, see Chapter 5, "Defining SQL Queries Using View Objects."
Figure 1-11 shows the oracle.summit.model.view package, which contains many of the queries needed by the application.
Figure 1-11 View Objects in the Summit ADF Sample Application
Additionally, you may find that you need to expose functionality to external applications. You can do this by exposing this functionality through a service interface. For example, the ServiceAppModule application module is exposed as a web service. This web service exposes the CustomersView and OrdersView view instances, as shown in Figure 1-12. For more information, see Chapter 15, "Creating SOAP Web Services with Application Modules."
Figure 1-12 The ServiceAppModule Application Module as a Web Service
While you develop your application, you can iteratively test your business services using the Oracle ADF Model Tester. The tester allows you to test the queries, business logic, and validation of your business services without having to use or create a user interface or other client to test your services. Using the tester allows you to test out the latest queries or business rules you've added, and can save you time when you're trying to diagnose problems. For more information about developing and testing application modules, see Chapter 13, "Implementing Business Services with Application Modules."
The tester also interacts with the ADF Declarative Debugger to allow debug your business services. You can set breakpoints on any custom methods you create. For more information, see Section 42.7, "Using the Oracle ADF Model Tester for Testing and Debugging."
From the page flows you created during the planning stages, you can double-click the page icons to create the actual JSF files. When you create a JSF page for an ADF Faces application, by default, you create a Facelets XHTML file that uses the .jsf extension. Facelets is a JSF-centric XML view definition technology that provides an alternative to using the JSP engine.
While Facelet pages can use any well formed XML file, when you create a Facelet page in JDeveloper, it is created as an XHTML file.
ADF Faces provides a number of components that you can use to define the overall layout of the page. JDeveloper contains predefined quick start layouts that use these components to provide you with an efficient way to correctly determine the layout of your pages. You can choose from one-, two-, or three-column layouts, and then determine how you want the columns to behave. You can also choose to apply themes to the layouts, which adds color to some of the components for you. For more information see the "Using Quick Start Layouts" section of Developing Web User Interfaces with Oracle ADF Faces .
Oracle ADF also allows you to create and use your own page templates. When creating templates, you can determine the layout of the page (either using one of the quick layout templates or creating the layout manually), provide static content that must appear on all pages, and create placeholder attributes that can be replaced with valid values for each page. Each time the template is changed, for example if the layout changes, any page that uses the template will reflect the update.
The chapters in Part I, "Creating a Databound Web User Interface" provide information on creating different types of UI functionality, from basic forms to more complex search capabilities.
In a typical JSF application, you bind the UI component attributes to properties or methods on managed beans. The JSF runtime manages instantiating these beans on demand when any EL expression references them for the first time. However, in an application that uses ADF Model, JDeveloper automatically binds the UI component attributes to ADF Model, which uses XML configuration files that drive generic data binding features. It implements concepts that enable decoupling the user interface technology from the business service implementation: data controls and declarative bindings .
Data controls use XML configuration files to describe a service. At design time, visual tools like JDeveloper can leverage that metadata to allow you to declaratively bind UI components to any data control operation or data collection, creating bindings. For example, Figure 1-13 shows the BackOfficeAppModuleDataControl data control as it appears in the Data Controls panel of JDeveloper.
Figure 1-13 BackOfficeAppModuleDataControl
Note that the collections that display in the panel represent the set of rows returned by the query in each view object instance contained in the BackOfficeAppModuleDataControl application module. For example, the Countries data collection in the Data Controls panel represents the Countries view object instance in the BackOfficeAppModuleDataControl's data model. The attributes available in each row of the respective data collections appear as child nodes. The data collection level Operations node contains the built-in operations that ADF Model supports on data collections, such as previous , next , first , last , and so on.
If you create other kinds of data controls for working with web services, XML data retrieved from a URL, JavaBeans, or EJBs, these would also appear in the Data Controls panel with an appropriate display. When you create one of these data controls in a project, JDeveloper creates metadata files that contain configuration information. These additional files do not need to be explicitly created when you are working with Oracle ADF application modules, because application modules are already metadata-driven components, and so contain all the information necessary to be exposed automatically as ADF Model data controls.
Using the Data Controls panel, you can drag and drop a data collection onto a page in the visual editor, and JDeveloper creates the necessary bindings for you. Figure 1-14 shows the Countries collection being dragged from the Data Controls panel, and dropped as a form onto a JSF page.
Figure 1-14 Declaratively Creating a Form Using the Data Controls Panel
The first time you drop a databound component from the Data Controls panel on a page, JDeveloper creates an associated page definition file . This XML file describes the group of bindings supporting the UI components on a page. ADF Model uses this file at runtime to instantiate the page's bindings. These bindings are held in a request-scoped map called the binding container . Each time you add components to the page using the Data Controls panel, JDeveloper adds appropriate binding entries into this page definition file. Additionally, as you perform drag and drop data binding operations, JDeveloper creates the required tags representing the JSF UI components on the JSF page. For more information about using the Data Controls panel, see Chapter 17, "Using ADF Model in a Fusion Web Application."
Aside from forms and tables that display or update data, you can also create search forms, and databound charts and graphs. For more information about using data controls to create different types of pages, see the chapters contained in Part I, "Creating a Databound Web User Interface". For more information about the Data Controls panel and how to use it to create any UI data bound component, see Chapter 17, "Using ADF Model in a Fusion Web Application." For detailed information about ADF Model, see Developing Applications with Oracle ADF Data Controls .
You can add validation to your business objects declaratively using the overview editors for entity and view objects. In the case of entities, the business rules always reflect the data type constraints defined on the attributes.
Figure 1-15 shows the Business Rules page of the overview editor for the EmpEO entity object.
Figure 1-15 Setting Validation in the Overview Editor
Along with providing the validation rules, you also set the error messages to display when validation fails. To supplement this declarative validation, you can also use Groovy-scripted expressions. For more information about creating validation at the service level, see Chapter 11, "Defining Validation and Business Rules Declaratively."
Additionally, ADF Faces input components have built-in validation capabilities. You set one or more validators on a component either by setting the required attribute or by using the prebuilt ADF Faces validators. You can also create your own custom validators to suit your business needs. For more information, see the "Validating and Converting Input" chapter of Developing Web User Interfaces with Oracle ADF Faces .
You can create a custom error handler to report errors that occur during execution of an application. Once you create the error handler, you only need to register the handler in one of the application's configuration files.
Oracle ADF provides a security implementation that is based on Java Authentication and Authorization Service (JAAS). It enables applications to authenticate users and enforce authorization. The Oracle ADF implementation of JAAS is permission-based. You define these permissions and then grant them on application roles that you associate with users of the application. For more information about securing your application, see Chapter 41, "Enabling ADF Security in a Fusion Web Application."
Testing an Oracle ADF web application is similar to testing and debugging any other Java EE application. Most errors result from simple and easy-to-fix problems in the declarative information that the application defines or in the EL expressions that access the runtime objects of the page's ADF binding container. In many cases, examination of the declarative files and EL expressions resolve most problems.
For errors not caused by the declarative files or EL expressions, you can use the ADF Logger, which captures runtime trace messages from ADF Model API. The trace includes runtime messages that may help you to quickly identify the origin of an application error. You can also search the log output for specific errors.
JDeveloper also includes the ADF Declarative Debugger, a tool that allows you to set breakpoints on declarative aspects of Oracle ADF, such as the binding layer, taskflows and more. When a breakpoint is reached, the execution of the application is paused and you can examine the data that the ADF binding container has to work with, and compare it to what you expect the data to be. Chapter 42, "Testing and Debugging ADF Components" contains useful information and tips on how to successfully debug a Fusion web application.
For testing purposes, JDeveloper provides integration with JUnit. You use a wizard to generate regression test cases. For more information, see Section 42.11, "Regression Testing with JUnit."
Using JDeveloper, you can easily rename or move the different components in your application. When you use JDeveloper to refactor the business components of your data model project, you can rename components or move them to a different package and JDeveloper will find and update all references to the refactored component. Whenever possible, you should use JDeveloper's refactoring actions to avoid error-prone manual editing of the project. For more information, see Chapter 43, "Refactoring a Fusion Web Application."
You can deploy a Fusion web application to either the integrated WebLogic server within JDeveloper or to a supported standalone instance. For more information about deployment, see Chapter 49, "Deploying Fusion Web Applications."
You can build your Fusion web application so that it can easily integrate with other applications. You can publish your application modules as services.You can also create events that can be used for example, to initiate business processes. For more information, see Chapter 15, "Creating SOAP Web Services with Application Modules." Your application modules can also call other web services directly. For more information, see Section 13.12, "Calling a Web Service from an Application Module." You can also integrate your application using task flows. For example, a task flow can be used to initiate a business process flow.
Often, applications are built in a team development environment. While a team-based development process follows the development cycle outlined in Section 1.3, "Overview of Building an Application with Oracle ADF,"many times developers are creating the different parts of the application simultaneously. Working productively means team members divide the work, understand how to enforce standards, and manage source files with a source control system, in order to ensure efficient application development.
oracle offers the Oracle Team Productivity Center, a feature of JDeveloper that provides access to a set of application lifecycle management (ALM) tools and technologies. For more information, see Developing Applications with Oracle Team Productivity Center .
Before beginning development on any large application, a design phase is typically required to assess use cases, plan task flows and screens, and identify resources that can be shared.
The following list shows how the work for a typical Fusion web application might be broken up once an initial design is in place:
Because numerous individuals divided into separate teams will be developing the application, you should enforce a number of standards before development begins to ensure that all components of the application will work together efficiently. The following are areas within an application where it is important to have standardization in place when working in a team environment:
When working in a team environment, you will need to use a source control system. By default, JDeveloper provides support for the Subversion source control system, and others (such as CVS) are available through extensions. You can also create an extension that allows you to work with another system in JDeveloper. For information about using these systems within JDeveloper, see the "Versioning Applications with Source Control" chapter of Developing Applications with Oracle JDeveloper .
Following are suggestions for using source control with a Fusion web application:
As you'll learn throughout the rest of this guide, JDeveloper and Oracle ADF give you a productive, visual environment for building richly functional, database-centric Java EE applications with a maximally declarative development experience. However, if you are used to working with tools like Oracle Designer that offer complete user interface generation based on a higher-level application structure definition, you may be looking for a similar facility for your Java EE development. If so, then the Oracle JHeadstart application generator may be of interest to you. It is an additional extension for JDeveloper that uses Oracle ADF's built-in features to offer complete web-tier generation for your application modules. Starting with the data model you've designed for your ADF business service, you use the integrated editors that JHeadstart adds to the JDeveloper environment to iteratively refine a higher-level application structure definition. These editors control the functionality and organization of the view objects' information in your generated web user interface. By checking boxes and choosing various options from dropdown lists , you describe a logical hierarchy of pages that can include multiple styles of search regions, list of values (LOVs) with validation, shuttle controls, nested tables, and other features. These declarative choices use terminology familiar to Oracle Forms and Designer users, further simplifying web development. Based on the application structure definition, you generate a complete web application that automatically implements the best practices described in this guide, easily leveraging the most sophisticated features that Oracle ADF and JSF have to offer.
Whenever you run the JHeadstart application generator, rather than generating code , it creates (or regenerates) all of the declarative view and controller layer artifacts of your Oracle ADF-based web application. These artifacts use ADF Model and work with your ADF application module as their business service. The generated files are the same kinds you produce when using the JDeveloper built-in visual editors. The key difference is that JHeadstart creates them in bulk, based on a higher-level definition that you can iteratively refine until the generated pages match your end users' requirements as closely as possible. The generated files include:
Once you've generated a maximal amount of your application's web user interface, you can spend your time using the productive environment of JDeveloper to tailor the results or to concentrate your effort on additional showcase pages that need special attention. Once you've modified a generated page, you can adjust a setting to avoid regenerating that page on subsequent runs of the application generator. Of course, since both the generated pages and your custom designed ones leverage the same ADF Faces UI components, all of your pages automatically inherit a consistent look and feel. For more information on how to get a fully functional trial of JHeadstart for evaluation, including details on pricing, support, and additional services, see the JHeadstart page on the Oracle Technology Network at:
In addition to this developers guide, Oracle also offers the following resources to help you learn how you can best use Oracle ADF in your applications: