1 Introduction to Building Java EE Web Applications with Oracle ADF

This chapter describes the architecture and key functionality of the Oracle Application Development Framework (Oracle ADF) when used to build a web application with session and entity beans that use EJB 3.0 annotations and the Java Persistence API (JPA), along with ADF Model, ADF Controller, and ADF Faces rich client. This chapter also discusses high-level development practices.

This chapter includes the following sections:

1.1 Introduction to Oracle ADF

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 to simplify and accelerate implementing service-oriented applications. If you develop enterprise solutions that search, display, create, modify, and validate data using web, wireless, desktop, or web services interfaces, Oracle ADF can simplify your job. Used in tandem, Oracle JDeveloper 11g 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.

Figure 1-1 illustrates where each Oracle ADF module fits in the web application architecture. The core module in the framework is ADF Model, which is a declarative data binding facility. The ADF Model layer 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 the application technology stack aside from EJBs, are:

  • ADF Faces rich client, which offers a rich library of AJAX-enabled UI components for web applications built with JavaServer Faces (JSF). For more information about ADF Faces, refer to the Oracle Fusion Middleware Web User Interface Developer's Guide for Oracle Application Development Framework.

  • ADF Controller, which integrates JSF with ADF Model. The ADF Controller extends the standard JSF controller by providing additional functionality, such as reusable task flows that pass control not only between JSF pages, but also between other activities, for instance method calls or other task flows. For more information about ADF Controller, see "Part III Creating ADF Task Flows" of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

Note:

In addition to ADF Faces, Oracle ADF also supports using the Swing, JSP, and standard JSF view technologies. For more information about these technologies, refer to the JDeveloper online help. Oracle ADF also provides support for using Microsoft Excel as a view layer for your application. For more information, see the Oracle Fusion Middleware Desktop Integration Developer's Guide for Oracle Application Development Framework

Figure 1-1 Simple Oracle ADF Architecture

Image of ADF architecture

1.2 Developing with Oracle ADF

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 11g 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.

Note:

This guide covers developing an application with session and entity beans using EJB 3.0 annotations and JPA (Java Persistence API) for model persistence, along with the Oracle ADF Model layer, ADF Controller, and ADF Faces. This process is very similar to developing a Fusion web application. The main difference is that a Fusion web application uses ADF Business Components for the back-end services. When the development process and procedures are the same for both application types, this guide refers you to the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework for that information.

Please disregard any information in the Fusion Developer's guide regarding ADF Business Components (such as entity objects and view objects). For similar information for EJB/JPA, refer to the "Developing EJB and JPA Components" topic in the JDeveloper online help.

At a high level, the declarative development process for a Java EE web application usually involves the following:

  • Creating an application workspace: Using a wizard, JDeveloper automatically adds the libraries and configuration needed for the technologies you select, and structures your application into projects with packages and directories. For more information, see the "Creating an Application Workspace" section of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  • Modeling the database objects: You can create an offline replica of any database, and use JDeveloper editors and diagrammers to edit definitions and update schemas. For more information, see the "Modeling with Database Object Definitions" section of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  • Creating use cases: Using the UML modeler, you can create use cases for your application. For more information, see the "Creating Use Cases" section of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  • Designing application control and navigation: You use diagrammers to visually determine the flow of application control and navigation. JDeveloper creates the underlying XML for you. For more information, see the "Designing Application Control and Navigation using ADF Task Flows" section of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  • Identifying shared resources: You use a resource library that allows you to view and use imported libraries by simply dragging and dropping them into your application. For more information, see the "Identifying Shared Resources" section of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  • Creating the persistence model: From your database tables, you create EJB 3.0 entity beans using wizards or dialogs. From those beans, you create the session bean as the facade that will be used by the pages in your application. You can implement validation rules and other types of business logic using editors on the metadata files that describe the session bean and its underlying entity beans. For more information about using JDeveloper with EJBs, see the "Developing EJB and JPA Components" topic in the JDeveloper online help.

  • Creating data controls for your services: Once you've created your entity and session beans, you create the data controls that use metadata interfaces to abstract the implementation of your EJBs, and describe their operations and data collections, including information about the properties, methods, and types involved. These data controls are displayed in the Data Controls Panel. For more information, see Chapter 2, "Using ADF Model Data Binding in a Java EE Web Application."

  • Binding UI components to data using the ADF Model layer: When you drag an object from the Data Controls panel, JDeveloper automatically creates the bindings between the page and the data model. For more information, see Chapter 2, "Using ADF Model Data Binding in a Java EE Web Application."

  • Implementing the user interface with JSF: JDeveloper's Data Controls panel contains a representation of the beans for your application. Creating a user interface is as simple as dragging an object onto a page and selecting the UI component you want to display the underlying data. For UI components that are not databound, you use the Component Palette to drag and drop components. JDeveloper creates all the page code for you. For more information, see the "Implementing the User Interface with JSF" section in the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

    For information about creating specific types of web pages, see the following in this guide:

  • Incorporating validation and error handling: Once your application is created, you use editors to add additional validation and to define error handling. For more information, see Section 2.3.5, "What You May Need to Know About Configuring Validation."

  • Developing pages and applications to allow customization: Using the customization features provided by the Oracle Metadata Services (MDS), you can create applications that customers can customize yet still easily accept upgrades, create pages that allow end users to change the application UI at runtime, and create applications that are completely customizable at runtime. For more information, see the "Customizing Applications with MDS" and "Allowing User Customizations at Runtime" chapters of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  • Securing the application: You use editors to create roles and populate these with test users. You then use a flat file editor to define security policies for these roles and assign them to specific resources in your application. For more information, see the "Enabling ADF Security in a Fusion Web Application" chapter in the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  • Testing and debugging: JDeveloper includes an integrated application server that allows you to fully test your application without needing to package it up and deploy it. JDeveloper also includes the ADF Declarative Debugger, a tool that allows you to set breakpoints and examine the data. For more information, see the "Testing and Debugging ADF Components" chapter of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  • Deploying the application: You use wizards and editors to create and edit deployment descriptors, JAR files, and application server connections. For more information, see Chapter 8, "Deploying an ADF Java EE Application."

1.3 Introduction to the ADF Sample Application

As a companion to this guide, the Suppliers module of the Fusion Order Demo application was created to demonstrate the use of the Java EE and ADF web application technology stack to create transaction-based web applications as required for a web supplier management system. The demonstration application is used to illustrate points and provide code samples.

Before examining the individual components and their source code in depth, you may find it helpful to install and become familiar with the functionality of the Fusion Order Demo application. See the following sections of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework for information:

1.3.1 Running the Suppliers Module of the Fusion Order Demo Application

The Suppliers module consists of a business services project named Model and a web user interface project named ViewController. You run the Suppliers module of the Fusion Order Demo application in JDeveloper by running the ViewController project. The ViewController project uses JavaServer Faces (JSF) as the view technology, and relies on the ADF Model layer to interact with the EJBs in the Model project. To learn more about the Suppliers module and to understand its implementation details, see Section 1.3.2, "Taking a Look at the Supplier Module Code" and Section 1.3.3, "Touring the Supplier Module."

To run the Suppliers module of the Fusion Order Demo application:

  1. Download and install the Fusion Order Demo application as described in the "Setting Up the Fusion Order Demo Application" section of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

  2. Open the application in Oracle JDeveloper:

    1. From the JDeveloper main menu, choose File > Open.

    2. Navigate to the location where you extracted the demo ZIP file to and select the SupplierModule_2.0.jws application workspace from the SupplierModule directory. Click Open.

      Figure 1-2 shows the Application Navigator after you open the file for the application workspace. For a description of each of the projects in the workspace, see Section 1.3.2, "Taking a Look at the Supplier Module Code."

      Figure 1-2 The Supplier Module Projects in Oracle JDeveloper

      FOD application project folders
  3. In the Application Navigator, click the Application Resources accordion title to expand the panel.

  4. In the Application Resources panel, expand the Connections and Database nodes.

  5. Right-click FOD connection and choose Properties.

  6. In the Edit Database Connection dialog, modify the connection information shown in Table 1-1 for your environment.

    Table 1-1 Connection Properties Required to Run the Fusion Order Demo Application

    Property Description

    Host Name

    The host name for your database. For example:

    localhost

    JDBC Port

    The port for your database. For example:

    1521

    SID

    The SID of your database. For example:

    ORCL or XE


    Do not modify the user name and password fod/fusion. These must remain unchanged. Click OK.

  7. In the Application Navigator, right-click Model and choose Rebuild.

  8. In the Application Navigator, right-click ViewController and choose Run.

    The login.jspx page is displayed. Because of the way security is configured in this module, you must first log in.

  9. Enter SHEMANT for User Name and welcome1 for Password.

Once you log in, the browse page appears, which allows you to search for products. Once you select a product in the results table, you can edit or remove the product information. Using the command links at the top of the page, you can edit the corresponding supplier's information, or add a new supplier. For more information about the Suppliers module at runtime, see Section 1.3.3, "Touring the Supplier Module."

1.3.2 Taking a Look at the Supplier Module Code

Once you have opened the projects in Oracle JDeveloper, you can then begin to review the artifacts within each project. The Model project contains the Java classes and metadata files that allow the data to be displayed in the web application. The oracle.fodemo.common project contains components used by multiple classes in the application. The oracle.fodemo.supplier project contains the components used to access the supplier data. Figure 1-3 shows the Model project and its associated directories.

Figure 1-3 The Model Project in JDeveloper

Directories in the Model project

The ViewController project contains the files for the web interface, including the backing beans, deployment files, and JSPX files. The Application Sources node contains the code used by the web client, including the managed and backing beans, property files used for internationalization, and the metadata used by Oracle ADF to display bound data. The Web Content node contains web files, including the JSP files, images, skin files, deployment descriptors, and libraries. Figure 1-4 shows the ViewController project and its associated directories.

Figure 1-4 The ViewController Project in JDeveloper

Directories in the ViewController project

1.3.3 Touring the Supplier Module

The Supplier module contains eight main pages that allow a user to perform the following functionality:

  • Search for products: The browse.jspx page allows a user to search for products. Search results are displayed in a table. Figure 1-5 shows the search form on the browse page.

    Figure 1-5 Search Form in Supplier Module

    Search form in supplier module
  • Edit row data in a table: From the table on the browse.jspx page, a user can select a product and choose Update to navigate to the productInfo.jspx page (clicking the product link also navigates to this page). From the table, a user can also click Remove, which launches a popup that allows the removal of the selected product. Figure 1-6 shows the table on the browse page.

    Figure 1-6 Table on the browse Page

    Table on the browse page
  • Edit row data in a form: From the productInfo.jspx page, a user can change the data for a row. A selection list contains valid values for the product status. The Choose File button allows a user to upload a graphic file, which is then displayed below the form. Figure 1-7 shows the productInfo page.

    Figure 1-7 The productInfo Page

    productInfo page
  • The Add Supplier link takes the user to a series of pages contained within the regisrationDetails.jspx page that are used to create a new supplier, as shown in Figure 1-8.

    Figure 1-8 Create a Supplier Train

    Create a Supplier train
    • For information about creating a train, see the "Creating a Train" section of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.

    • For information about creating forms that allow users to create new records, see Section 3.7, "Creating an Input Form."

  • Log in to the application: The login.jspx page allows users to log in to the application. For more information, see the "Enabling ADF Security in a Fusion Web Application" chapter of the Oracle Fusion Middleware Fusion Developer's Guide for Oracle Application Development Framework.