Developing Web Applications with Oracle ADF Essentials

By Sten E. Vesterli
    Advance your knowledge in tech with a Packt subscription

  • Instant online access to over 7,500+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies

About this book

With ADF, Oracle gives you the chance to use the powerful tool used by Oracle’s own developers. Modern enterprise applications must be user-friendly, visually attractive, and fast performing. Oracle Fusion Applications are just that; but to get the desired output you need proven methods to use this powerful and flexible tool to achieve success in developing your enterprise applications.

"Developing Web Applications with Oracle ADF Essentials" explains all you need to know in order to build good-looking, user-friendly applications on a completely free technology stack. It explains the highly productive, declarative development approach that will literally have your application running within a few hours, as well as how to use Java to add business logic.

"Developing Web Applications with Oracle ADF Essentials" tells you how to develop and deploy web application applications based on the highly productive and free Oracle ADF Essentials framework. You will first learn how to build business services on top of database tables, and then how to easily build a web application using these services. You will see how to visually design the flow through your application with ADF task flows, and how to use Java programming to implement business logic. Using this book, you can start building and deploying advanced web applications on a robust, free platform quickly.

Towards the end, you will be ready to build real-world ADF Essentials applications and will be able to consider yourself an ADF Essentials journeyman.

Publication date:
August 2013
Publisher
Packt
Pages
270
ISBN
9781782170686

 

Chapter 1. My First ADF Essentials Application

In this chapter, we will install all the necessary (free!) software that we will be using throughout the book to build applications using Oracle Application Development Framework (ADF). We'll need:

  • A database

  • Java Development Kit and an application server

  • The Oracle ADF Essentials libraries

  • A development tool

For the purposes of this book, we will be using the popular and free MySQL database. However, you can run Oracle ADF Essentials applications on any other SQL database—so if you're a PostgreSQL fan, you don't have to change. You can also use commercial databases—Oracle is offering Oracle Database Express Edition if you are looking for a free version of an enterprise product.

Tip

Don't plan on running Oracle Database Express Edition directly on your development machine if it is 64-bit Windows—this is not supported and won't work. To run Oracle XE, you'll either need Linux, an old 32-bit Windows install, or run your database inside a 32-bit Windows virtual machine.

Similarly, you can run your ADF Essentials application on any JEE application server. This book will describe how to use GlassFish, but you could also use other open source JEE servers like JBoss or commercial offerings like Oracle WebLogic.

As our development tool, we will be using Oracle's preferred development tool, Oracle JDeveloper. This free tool is currently the only supported way of building Oracle ADF Essentials applications, but Oracle is working on supporting ADF Essentials as part of their Oracle Enterprise Pack for Eclipse (OEPE) product.

Tip

With Eclipse and Oracle Enterprise Pack for Eclipse, you can already build ADF applications for WebLogic. However, the tool does not yet support building applications for ADF Essentials.

 

Getting ready


To simplify the instructions in this book, you should create a directory called adfessentials and install everything there.

On Windows, place this directory in the root of your C: drive as C:\adfessentials.

On Mac/Linux, place this directory in the root of your filesystem as /adfessentials. You will typically be prompted for a system administrator or root password when creating the directory.

 

Installing MySQL


The MySQL server exists in both a Community Server edition and an Enterprise Edition. The Enterprise Edition is the commercial version that has additional features and a price tag—in this book, we will use the free Community Server edition Version 5.6.12. This can be downloaded from http://dev.mysql.com/downloads/mysql.

Note

Would you like support with that?

Now is a good time to think about whether you want your installation to be commercially supported. If you are setting up a development environment or just want to run a membership application for your local little league baseball team, you probably don't need commercial support and can go with the open source/community options.

On the other hand, if you are setting up a production environment, think about whether you or someone else in your organization feels confident that they can handle any issues that might occur. If you would like to be able to call on the friendly people from Oracle Support to help you, you need to set up the commercial version and purchase a support contract from Oracle.

If you choose the Windows platform, you will be given the option to download the MySQL Installer MSI package as shown in the following screenshot:

When you click on the Download link, you will be taken to a page where you can select from two MSI Installer packages as shown in the following screenshot:

Choose the larger one to get everything in one download. The smaller option means that you download only the installer program first, and this program will then download the rest of the software.

If you are running Mac OS X, you have an option to select either a compressed TAR file or a DMG installer as shown in the following screenshot:

For the easiest installation, choose the DMG installer file that matches your OS X version and architecture. If you have a fairly recent Mac, you should choose OS X 10.7, 64-bit.

If you are running Linux, choose your distribution from the Platform options (or Linux – Generic if your distribution is not listed), and then choose the download that matches your Linux version and architecture (32- or 64-bit).

Once you have chosen your download, you will be prompted to sign up for a free Oracle Web account (or log in with an existing account) when you click on the Download link. You will need this account in order to download the ADF Essentials software and JDeveloper, and probably later for other downloads as well.

MySQL installation

This section will walk you through the installation of the MySQL database on Windows – if you are running another operating system, the process is similar.

Tip

Some installation options of some Linux distributions install MySQL by default. If you are running Linux, you might want to check if you already have MySQL.

Start the installer, click on OK to any warnings about installing software and changing your machine, and choose Install MySQL Products. Read and accept the license agreement and allow it to check for later versions of the software.

For the purposes of this book, you can simply choose a Developer Default setup type when prompted. If you already know MySQL and have specific ideas about your installation, feel free to change the options.

Change the installation path to C:\adfessentials\MySQL\product and the data path to C:\adfessentials\MySQL\data.

Note

On Mac and Linux, the installer might simply decide to place the software and data in /usr/local. That's fine, too.

In the Check Requirements step, you may be prompted to install various additional packages—simply accept this. If you are told that you are missing various versions of the Python programming language, you can just click on Execute a few times to acknowledge the warnings.

Note

The Developer Default installation includes database connectors for Python, but if you are not using Python, they can't be installed. That's OK.

Once you are done with this step, the installer starts installing the actual MySQL software as shown as follows:

Configuring

When the software is installed, you can click on Next a few times to start the configuration. The first screen looks like this:

On this screen, you can leave the defaults:

  • Development Machine

  • Enable TCP/IP

  • Port Number 3306

  • Open Firewall for network access

In step 2 shown in the following screenshot, you are asked to provide a root password for the database. You can always create separate users later.

Tip

If this is a non-critical development workstation, and you want to be sure that you have the password written down, feel free to use this example password: ADFsecret/13.

Tip

The default installation on Mac and Linux sets a blank root password, which is probably a bit too relaxed. To set the password on Mac/Linux, execute the following command:

/usr/local/mysql/bin/mysqladmin –u root –p password

Press return when prompted for a password (the prompt is for the old, empty password) and then provide a new password twice.

In step 3, you are prompted for a Windows service name as shown in the following screenshot:

You can leave the defaults on this screen.

When you click on Next, the configuration of MySQL runs. When this is complete, click on Next to install the samples and examples and then finish the installation.

Changing MySQL options

JDeveloper generates code with two vertical bars (|| or pipes) for string concatenation, and while this is valid SQL92, it is not supported in a default MySQL configuration. To enable this in MySQL, find the MySQL configuration file my.ini in the database directory (for example, C:\adfessentials\MySQL\data).

Search for a line starting with sql_mode=. If such a line exists, add a comma after the existing value and then the keyword PIPES_AS_CONCAT. If there is no sql_mode line, add the following:

sql_mode=PIPES_AS_CONCAT

If you come from an Oracle background, you might want to set sql_mode=ORACLE instead—this sets PIPES_AS_CONCAT and a couple of other settings to make MySQL behave more Oracle-like.

You will need to restart the MySQL database in order for this change to take effect. On Windows, you can open the Control Panel, choose Administrative Tools, and then Services. Find the MySQL56 service and choose Action | Restart. You can also restart the database from the MySQL Workbench by double-clicking on your database in the Server Administration column to the right.

Does it work?

Once you have your Sakila database installed, you can start the MySQL Workbench from the Start menu. You should see Local instance MySQL56 or similar to the left under the SQL Development heading, as shown in the following screenshot:

You can double-click on this and provide your root password to connect to the database. If an SQL Editor window opens with various schemas to the left (including your Sakila database) as shown in the following screenshot, your installation was successful:

If you prefer to use a command line, you can start the MySQL 5.6 Command Line Client from the Start menu, provide your root password, and type the following command:

show databases;

If you see a couple of databases as in the following screenshot, your MySQL server is running correctly:

The MySQL command line can also be started from a command prompt by running the following command:

C:\adfessentials\MySQL\product\bin\mysql –u root -p

This attempts to log in as user root and prompts you for the password.

Tip

On Mac and Linux, the MySQL Workbench is a separate package. You can either download and install it or check your installation using the command line:

/usr/local/mysql/bin/mysql –u root –p

Modifying some data

As installed, the Sakila database does not contain any DVDs not returned—every rental record has a return_date.

Because we will be building a screen to return DVDs, we want some unreturned rentals in the database. From either MySQL Workbench or the command line, execute the following command:

update rental set return_date = null where staff_id = 2;

This clears the return date for about half the rentals, making them unreturned.

 

Installing Java Development Kit and GlassFish


In order to be able to install and run GlassFish, your system first needs to have JDK 7 installed.


Installing JDK 7

You can download Java Development Kit 7 from http://www.oracle.com/technetwork/java/javase/downloads. You need the JDK download as shown in the following screenshot:

Accept the license agreement and choose the right bundle for your operating system and architecture, for example, Windows x64 for 64-bit Windows or Windows x86 for 32-bit Windows.

When the installation is complete, double-click on the downloaded file to install the JDK. In the second step of the install wizard, change the directory to one placed under your adfessentials folder, for example, C:\adfessentials\jdk1.7.0_25 as shown in the following screenshot:

When asked where to install the JRE, change the destination folder to C:\adfessentials\jre7 as shown in the following screenshot:

When the installation is complete, you need to set your JAVA_HOME environment variable to point to the JDK directory (for example, C:\adfessentials\jdk1.7.0_25).

Installing GlassFish

Note

At the time of writing, Version 4.0 of GlassFish has been released, but you cannot run ADF Essentials on it. So, this book will concentrate on GlassFish 3.1.

GlassFish Server Open Source Edition 3.1.2.2 can be downloaded from http://glassfish.java.net/download-archive.html. Like MySQL, GlassFish exists in both an open source version and a commerical version—if you want the commercial version, it can be found on the Oracle Technology Network under Middleware, GlassFish Server.

As the following screenshot shows, there are install sets available for Windows, Linux, Unix, Mac, and so on. Just click on the link for the file that matches your environment:

GlassFish installation

To install GlassFish, change to the directory where you downloaded the file and execute the following command:

glassfish-3.1.2.2-windows.exe –j c:\adfessentials\jdk1.7.0_25

Note

The GlassFish installation file sometimes cannot find your Java Development Kit, especially on 64-bit Windows. The preceding command works in all environments.

In the GlassFish installer, choose the following options:

  • Installation type: Typical

  • Install directory: c:\adfessentials\glassfish3

  • Update tool: Don't choose this

    Tip

    You do not want your server to automatically update itself. If one of your applications is not compatible with the new server version, your users will experience that the application is suddenly down, and you will have no idea that it has happened until they tell you.

  • The installer runs and installs the GlassFish software shown as follows:

Setting up the domain

When the software is installed, the installer will prompt you to create a domain like this:

You can leave the default domain name and ports. You should set a password for the admin user—again, if this is a non-critical development workstation and you want to be sure that you have the password written down, feel free to use this example password: ADFsecret/13.

Tip

If you are already running an Oracle database on the same machine, change the default HTTP port to something other than the default 8080 (because an Oracle database by default installs a service on port 8080).

After the domain has been created and started, click on Next to see the installation summary as shown in the following screenshot:

When you click on Exit, you will be prompted to register your GlassFish server, but this is not mandatory.

Does it work?

In order to check if your GlassFish server is indeed running, you can enter the URL http://localhost:<port> (for example, http://localhost:8080) in your browser to see the Your server is now running confirmation message like this:

Installing the MySQL connector in GlassFish

In order to be able to connect from GlassFish to a database, you need a connector. GlassFish does not have a MySQL connector built-in, so you need to go to http://www.mysql.com/products/connector and download the JDBC Connector for MySQL (Connector/J). You may be prompted to log on to your Oracle Web account.

Unpack the file and copy the mysql-connector-java-5.1.25-bin.jar file (or whatever the version number is by the time you read this) into the lib directory of your GlassFish domain (C:\adfessentials\glassfish3\ glassfish\domains\domain1\lib or similar). Then, stop GlassFish and start it again (on Windows, the start and stop commands are found on the Start menu under GlassFish Server Open Source Edition).

Adding a DataSource to GlassFish

In order for your applications to be able to connect to your MySQL database, you need to define a DataSource. Your applications will refer to the DataSource by name, and the configuration on the GlassFish server defines which database the DataSource will connect to. This gives the application server administrator the necessary freedom to move the application between environments, move databases to other servers, and so on.

You can set up a DataSource though the GlassFish Server Administration Console. You specified the port for this service as the Admin port when you installed GlassFish. The default port is 4848, so you can point your browser to http://localhost:4848 to start the admin console.

Open the Resources node on the left and then JDBC. Click on JDBC Connection Pools and then click on New in order to create a new connection pool. Give it the name SakilaPool, choose javax.sql.DataSource as Resource Type, and choose MySql as Database Driver Vendor. Your screen should look like this:

On the next screen, scroll down to the Additional Properties section and sort the properties by name (by clicking in the Name header). Find the following settings and set their value as follows:

  • databaseName: sakila

  • password: ADFsecret/13 (or whatever other password you chose when you installed MySQL)

  • servername: localhost

  • user: root

When you have clicked on Finish to create the pool, click on the SakilaPool name and then click on the Ping button to test that GlassFish can connect to MySQL. You should see a Ping Succeded message as shown in the following screenshot:

Then, click on JDBC Resources and then click on New in order to create a new JDBC resource. Give it the JNDI name jdbc/SakilaDS and select the SakilaPool connection pool for this JDBC resource as shown in the following screenshot:

 

Installing ADF Essentials


In order to run ADF Essentials applications in GlassFish, you will need to install the ADF Share libraries in your GlassFish domain and you will need to configure the GlassFish Server JVM memory parameters.

Getting ADF Essentials

You can get the ADF Essentials package from the Oracle Technology Network—at the time of writing, the download URL is http://www.oracle.com/technetwork/developer-tools/adf/downloads. If this does not work, you can get to the Downloads for Oracle ADF 11g page by starting at the OTN homepage (http://otn.oracle.com), clicking Software downloads to the left, then scrolling down and clicking on JDeveloper and ADF, then selecting Application Development Framework to the left, and finally clicking on the Downloads tab.

The download page will look something like this:

Accept the license agreement (read it first!) and then scroll down to the Oracle ADF Essentials section shown in the following screenshot and download:

You may be asked to fill in a short survey before Oracle lets you have the software, and you'll probably be asked to accept the license agreement once more—just to be on the safe side.

The download you get is the adf-essentials.zip file.

Installing the ADF Share libraries in GlassFish

To install the ADF Share libraries in GlassFish, first unpack your adf-essentials.zip file in a temporary directory to a flat structure without the directories. You can use a command like unzip -j adf_essentials.zip to achieve this.

Tip

A default unzip will unpack to the same directory structure as the ZIP file. This will not work. You must unpack everything into one directory, ignoring the directory paths in the ZIP file.

Copy all the files to the lib directory of the GlassFish domain where you want to run ADF Essentials applications. If you performed the installation as described earlier in the chapter, the lib directory will be c:\adfessentials\glassfish3\glassfish\domains\domain1\lib.

Setting the GlassFish JVM parameters

Because ADF applications are a bit more memory-hungry than the average JEE application, you will need to change the GlassFish JVM settings.

In a web browser, go to the GlassFish Administration page (by default on port 4848 of the server where you installed GlassFish, for example, http://localhost:4848). Log in with the admin user you created during installation and go to Configurations | server-config | JVM Settings. Open the JVM Options tab. Find the option -XX:MaxPermSize= and set it to -XX:MaxPermSize=512m in order to allow GlassFish to allocate more memory than default. Your screen should look like this:

Also, add the new value -Doracle.mds.cache=simple.

Note

This value is read by the ADF framework and instructs it to not use MetaData Services. This feature is not part of ADF Essentials (only of full ADF)—if you forget to set this parameter, your ADF application will fail with an oracle.adf.share.ADFShareException: getMDSInstance error.

Then, click on Save and restart your GlassFish server. You might notice a Restart Required message in the top-left of your server administration window, like this:

You can click on the message to see why a restart is necessary and then click on the Restart button, or you can use the commands on the Windows Start menu.

Does it work?

There is no easy way to immediately determine if you installed ADF Essentials correctly into your GlassFish server, so we'll get right on to the task of building simple ADF Essentials applications to prove that your ADF Essentials libraries are indeed correctly installed.

 

Installing JDeveloper


Now your GlassFish server is ready to run ADF applications—but we still need a tool to build them.

JDeveloper or Eclipse?

There are two tools for building Oracle ADF applications: Oracle JDeveloper and Eclipse with Oracle Enterprise Pack for Eclipse. There are two kinds of ADF: Full ADF, which needs a WebLogic server (and a license fee), and ADF Essentials, which is free.

Note

ADF Essentials is enough to build most applications. Some features that are only available in Full ADF include ADF Mobile, ADF Desktop Integration, ADF Security, ADF remote taskflows, MetaData Services, and so on. Refer to the ADF Essentials FAQ for a full list: http://www.oracle.com/technetwork/developer-tools/adf/overview/adfessentialsfaq-1837249.pdf.

At the time of writing, JDeveloper was supported for developing both kinds of ADF applications, but Oracle Enterprise Pack for Eclipse is only supported for building applications for Full ADF. We can see the same in the following diagram:

Which JDeveloper?

There are two flavors of JDeveloper:

  • The 11g Release 1 branch (called 11gR1, version numbers 11.1.1.x. At the time of writing, the latest was 11.1.1.7.0)

  • The 11g Release 2 branch (called 11gR2, version numbers 11.1.2.x. At the time of writing, the latest was 11.1.2.3.0)

11.1.1.7.0 is actually the latest release, and Oracle are developing all of their big internal applications using 11gR1 versions. These are the ones that get bug fixes first and are the only ones to offer support for modern distributed version control tools like Git.

Unfortunately, only the 11gR2 branch has support for GlassFish, so this is the version we have to use for developing applications with ADF Essentials.

Note

Oracle is promising eventually to bring these two tracks together in a JDeveloper 12c version. If this version is available by the time you read this book, choose that one. It might also have support for GlassFish 4.0.

JDeveloper installation

You can download JDeveloper from the Oracle Technology Network (OTN) website at http://otn.oracle.com. Click on the Downloads link and you will normally find a link to JDeveloper under Popular Downloads to the right. If it's not there, find it via the download index on the left.

Read and accept the OTN JDeveloper License and download the latest version for your platform. At the time of writing, this was 11.1.2.4.0. You'll want the Studio edition because this one includes Oracle ADF. Choose the install for your platform—the Windows install is an .exe file, and the Linux install is an executable (.bin). For other platforms, you will need to get the Generic installer. If you need the Generic installer, refer to the installation guide (under Prerequisites & Recommended Install Process) for detailed instructions. If you're not signed in to www.oracle.com, you'll have to do so before you can download.

The installation of JDeveloper on Windows is straightforward—just run the jdevstudio11124install.exe file. When prompted for an install directory, select C:\adfessentials\Middleware111240. Choose to perform a Typical installation.

Tip

If you later decide to install other versions of JDeveloper on your development machine, keep each version in its own directory.

The first time you start JDeveloper, you will be prompted to select a role. Select Studio Developer and remove the checkmark in the Always prompt for role selection on startup box.

Installing the MySQL Connector in JDeveloper

By default, JDeveloper does not come with a connector to MySQL databases. However, you have already downloaded the JDBC Connector for MySQL (Connector/J) that you can use in JDeveloper as well.

To install it in JDeveloper, copy the mysql-connector-java-5.1.25-bin.jar file (or whatever the version number is by the time you read this) to C:\adfessentials\middleware111240\jdeveloper\jdev\lib.

Note

The driver just needs to be placed on JDeveloper's classpath—the preceding directory is one possible option.

Then, from within JDeveloper, choose Tools | Manage Libraries. Click on New to add a new library and call it MySQL Driver. Choose the Class Path node and click on Add Entry. Navigate to the C:\adfessentials\middleware111240\jdeveloper\jdev\lib directory, choose the JAR, file and click on Select.

Tip

Choose the JAR file itself, not the directory.

The Create Library dialog should look like this:

Click on OK twice to close the dialog boxes. Now you have the MySQL driver available for your projects.

Installing the GlassFish Server Extension

In order to make it easier to manage the GlassFish server from within JDeveloper, you should install the GlassFish Server Extension into JDeveloper.

In JDeveloper, choose Help, Check for Updates. In step 2 of the Check for Updates wizard, make sure that Open Source and Partner Extensions is checked. In step 3, find the Glassfish Server Extension and select it. Click on Next and then click on Finish, and allow JDeveloper to restart. When JDeveloper starts again, you should see some GlassFish icons on your toolbar, like this:

You also need to tell JDeveloper where you have installed GlassFish. Choose Tools | Preferences | GlassFish Preferences. If you only see a Load Extension button, click on it to load the GlassFish. Then, update all the paths to match your GlassFish installation. If you use the same directories as this book, your dialog box will look like this:

Connecting to the GlassFish server

If your GlassFish server is not running, start it. On Windows, this is done via Start | GlassFish Server Open Source Edition | Start Application Server, or you can use the new GlassFish icons on the toolbar in JDeveloper.

Choose File | New | Connections | Application Server Connection. Give your connection a name and choose Glassfish 3.1 as Connection Type. In step 2, provide the admin username (admin) and leave the password field blank (the default GlassFish install doesn't set an admin password). In step 3, you can leave the default hostname and ports.

In step 4 of the wizard, test the connection. You should see all tests successful as shown in the following screenshot if your GlassFish server is running and JDeveloper can connect to it:

 

Building a simple ADF Essentials application


All ADF applications consist of the following parts:

  • View layer: The View layer consists of your JSF pages.

  • Controller layer: The Controller layer consists of ADF Task Flows.

  • Model layer: The Model layer consists of the Data Controls that connect the View/Controller layers to the business service.

  • Business Service layer: The Business Service layer provides services to query and manipulate data. There are many ways to build business services—in this book, we will use ADF Business Components, but you can also use, for example, JPA Entities and EJB 3.0 Session beans, POJOs, web services, and so on.

  • Database layer: The Database layer is where your data is stored persistently.

This section will briefly take you through the necessary steps to create an ADF Essentials application with the simplest possible representation of all of these layers. If you follow the steps on your own environment, you will get a first-hand feel for ADF development with JDeveloper. The next chapters will explain the various parts in more detail.

Creating the application

To create the application, click on the New Application link in the Application Navigator or choose File | New | Applications. Choose Fusion Web Application (ADF).

Give your application a name, provide a directory, and enter an application package prefix. This prefix is used in Java package naming in the application, so it should adhere to your normal Java naming standards. If your organization has the Internet domain company.com, your application package prefix will normally be something like com.company.<application>, for example, com.company.adfdemo1.

You can leave the defaults for the Model and ViewController projects in the following steps of the wizard.

When you are done, your screen will look like the following screenshot, with your application name at the top of the Application Navigator to the right, two projects under it, and a quick start checklist for the application in the middle:

You can explore the checklist to get a feel for the steps in ADF application development—it includes both detailed task lists and links to relevant places in the documentation.

Database

We will be working on the film table in the MySQL Sakila demo database. To create a connection, choose File | New | Connections | Database Connection. Give your Connection Name, choose Connection Type as MySQL, fill in Username as root, and give the Password. Remember that the default port is 3306 and we use the default sakila database. Your screen should look like this:

In the Library field, click on Browse and select the MySQL Driver you created when you installed JDeveloper (it's under the User node in the Select Library dialog).

Click on Test Connection—if you get a Success! message, your driver is installed correctly and you have provided the right connection information.

Business service

To start building business services for your application, select the Model project in the Application Navigator and choose File | New | Business Tier | ADF Business Components | Business Components from Tables as shown in the following screenshot:

In the Initialize Business Components Project wizard, choose your Sakila connection, choose SQL92 as the SQL Platform, and choose Java as Data Type Map.

Note

The SQL Platform setting controls the SQL statements that ADF generates. If you know you'll be using a specific database, you can select it to allow ADF to build optimized SQL for that platform. SQL92 is a standard that is supported by all modern databases, including MySQL.

The Data Type Map setting controls the Java objects used by ADF. Unless you are using an Oracle database, select Java.

  1. In step 1 of the wizard, click on Query, choose the film table on the left, and use the > button to move it to the Selected box in order to create an entity object.

  2. In step 2, move the Film entity object to the Selected box on the right in order to create an entity-based view object.

  3. In step 3, don't change anything (that is, do not create any query-based view objects).

  4. In step 4, leave the defaults (that is, create an Application Module).

  5. In step 5, you can leave the defaults (that is, do not create a business component diagram). If you are curious, feel free to check the checkbox to see the documentation JDeveloper can automatically generate for you.

  6. In step 6, just click on Finish.

JDeveloper creates a number of objects for you—you can see them in the Application Navigator.

You can test your business components by right-clicking on the AppModule node (with the suitcase icon) and choosing Run as shown in the following screenshot:

This starts the Business Components Tester application shown in the following screenshot, which allows you to interact with your business service through a simple UI:

Model layer

The model layer is automatically created for you when you create the business components. You can see the available data elements and operations in the Data Controls palette in the Application Navigator as shown in the following screenshot:

Controller layer

In the controller layer, we define the screens that make up the application and the possible navigation flows between them. For now, we'll just use the Unbounded Task Flow that every ADF application has.

Open the ViewController project and then Web Content | Page Flows to see the adfc-config element that represents the Unbounded Task Flow. Double-click on this element to open a visual representation of the flow. It's empty at the moment because we haven't added any pages yet.

Drag a View activity in from the Component Palette on the left as shown in the following screenshot and give it a name (for example, FilmPage):

You'll notice that the view component has a yellow exclamation mark, indicating a warning. This means that we have added a view component to the task flow, but we have not actually defined the page yet. So, let's do that.

View layer

In the View layer, we define the actual JSF pages that make up the application. Simply double-click on the page you just created in the unbounded task flow to open the Create JSF Page wizard. Set Document Type to Facelets and leave the page layout at Blank Page. We'll get back to using layouts and page templates in a later chapter.

Click on OK to actually create the page and open it in JDeveloper. You'll see an empty page in the Design view.

Find the Data Controls panel to the left and expand it. Expand the AppModuleDataControl node and drag the FilmView1 object onto the page as shown in the following screenshot:

When you release it, JDeveloper will automatically prompt you for a choice of component. Choose Table | ADF Read-Only Table. In the Edit Columns dialog, check the Enable Sorting and Enable Filtering checkboxes and click on OK.

Your page will show a representation of an ADF table full of mysterious #{…xxx} labels and fields. They represent bindings to the data control and will be replaced with actual labels and data at runtime—we'll get back to this in a later chapter.

By default, your application gets a long and complicated URL. You can change this by right-clicking on the ViewController project and choosing Project Properties. Select the Java EE Application node and set the Java EE Web Context Root to something simpler. It will typically default to something like FilmApp1-ViewController-context-root—you can change this to something like FilmApp1.

Click on Save All to save your work.

Getting ready to deploy

There are some settings that you need to change in order to make your application run with ADF Essentials on GlassFish.

DataSource

You just want your application to include the name of your database connection, not the actual connection details. In order to ensure this, you need to right-click on your Model project and choose Project Properties. In the properties dialog, choose Deployment and then Edit to edit the deployment profile. Choose Connections and then Connection Name Only as shown in the following screenshot:

Then, click on OK a couple of times to close the dialog box.

Application module configuration

In the current version of JDeveloper, the default application module configuration does not work with GlassFish, so you need to change the bc4j.xcfg file.

Right-click on the Application Module in the Model project and choose Configurations. This opens the bc4j.xcfg file in the Overview mode. Find the Source tab at the bottom of this panel to see the actual contents of this file.

Find the two <Custom JDBCDataSource=…/> lines. If they start with java:comp/env, change them to look like this:

<Custom JDBCDataSource="jdbc/SakilaDS">

Change platform

Finally, you need to tell JDeveloper that you want to run your ADF Essentials application on the GlassFish platform. You do this in two places:

  • In the project properties for the ViewController project (choose Deployment and edit the deployment profile as shown in the preceding screenshot, choose Platform, and then GlassFish 3.1) as shown in the following screenshot:

  • In the application properties (choose Application | Application Properties on the menu, then Deployment, and edit the deployment profile as in the preceding screenshot. Choose Platform and then GlassFish 3.1).

Running your first ADF Essentials application

Now your first ADF Essentials application is ready to deploy and run!

Choose Application, Deploy. You should see a default deployment profile (something like FilmApp1_Project1_FilmApp1). Choose this default profile and choose Deploy to Application Server. Choose your GlassFish connection and click on Finish to deploy your application.

The log panel at the bottom of the JDeveloper window will show deployment messages on the Deployment tab.

[03:34:42 PM] ----  Deployment started.  ----
[03:34:42 PM] Target platform is  (Glassfish 3.1).
[03:34:42 PM] Retrieving existing application information
[03:34:42 PM] Running dependency analysis...
[03:34:42 PM] Building...
[03:34:49 PM] Deploying 2 profiles...
[03:34:51 PM] Wrote Web Application Module to C:\JDeveloper\mywork\FilmApp1\ViewController\deploy\FilmApp1_ViewController_webapp.war
[03:34:55 PM] Wrote Enterprise Application Module to C:\JDeveloper\mywork\FilmApp1\deploy\FilmApp1_Project1_FilmApp1.ear
[03:34:55 PM] Deploying Application...
[03:38:28 PM] Application Deployed Successfully.
[03:38:28 PM] Elapsed time for deployment:  3 minutes, 46 seconds
[03:38:28 PM] ----  Deployment finished.  ----

Have patience—it takes a while (up to several minutes) for JDeveloper to bundle up the necessary ADF Essentials libraries with your application and deploy it onto the GlassFish server.

Once the deployment is finished, you can run your application in a web browser. Your URL will be of the form http://<server>:<port>/<web context root>/faces/<page name>. Remember that you set the web context root in the properties of the ViewController project. In the preceding section on the controller layer, we set it to FilmApp1. An example of a URL would be http://localhost:8080/FilmApp1/faces/FilmPage.jspx. Your page should look like this:

Notice some of the cool features of the ADF table component we used:

  • You can resize the columns by dragging the column borders

  • You can reorder columns with drag-and-drop

  • New records are loaded as you scroll down (try dragging the slider on the vertical scrollbar)

  • You can sort columns by clicking on the header

  • You can filter data by entering filtering criteria in the filtering field over each column

 

Can it run faster?


Because the deployment from JDeveloper to GlassFish currently takes quite a long time, many developers choose to run their new code first in the WebLogic server that is pre-integrated into JDeveloper. If you set up WebLogic for MySQL, a simple application like the preceding should be able to start in 20-30 seconds instead of several minutes.

Tip

Hopefully, the deployment speed to GlassFish will be improved in the future. Check out the http://www.adfessentials.com for any tips about speeding up deployment that have been discovered after the publication of this book.

Setting up WebLogic for MySQL

If you want to run MySQL applications in the built-in WebLogic server, you first need to copy the MySQL Connector JAR (mysql-connector-java-5.1.25-bin.jar) to a directory where WebLogic can find it. A good choice is the directory for external libraries in the JRA installation: C:\adfessentials\middleware111240\jdk160_24\lib\ext.

Tip

If you are familiar with WebLogic, you should be able to place the MySQL connector in the WebLogic default domain lib directory. However, in JDeveloper 11.1.2.4, this does not work. Either use the preceding directory or modify the domain startup scripts.

Adding a DataSource to WebLogic

Once you have the driver installed, you need to define a datasource with the right name like you did earlier in the chapter for GlassFish.

First, in JDeveloper, start the built-in WebLogic server with the command Run | Start Server Instance. The first time you start the server, you will be prompted for a password to the default domain. Watch the messages in the log window until you see the following command:

<Server started in RUNNING mode>

Then, open a web browser and type in the address http://localhost:7101/console. Log in with the admin user and the password you provided. After a little while, the WebLogic console window opens.

Expand the Services node under Domain Structure to the left and select the Data Sources node. Click on New | Generic Data Source. Give your datasource a Name (SakilaDS) and a JNDI Name (jdbc/SakilaDS), and choose Database Type as MySQL. In the next two steps, just leave the defaults. On the Connection Properties page, provide your connection details:

  • Database Name: sakila

  • Host Name: localhost

  • Port: 3306

  • Database User Name: root

  • Password and Confirm Password: Your database root password, for example, ADFsecret/13

On the following screen, click on Test Configuration. You should see Connection test succeeded.

Click on Next (not Finish) and check the checkbox next to DefaultServer. Then, click on Finish.

Tip

In WebLogic, a JDBC driver definition is by default not connected to any server. If you forget to check the checkbox associating the SakilaDS datasource with the DefaultServer, the server can't connect to the database.

Running your first ADF Essentials application again

To run your first ADF Essentials application in the built-in WebLogic, server simply right-click on FilmPage in the Application Navigator and choose Run. The application will automatically be re-built, deployed to the built-in WebLogic server, and opened in a browser.

 

Summary


We've set up the entire infrastructure for building ADF Essentials applications: a MySQL database, the GlassFish server, and the JDeveloper integrated development environment. We have also installed the necessary interconnections and wired everything together so our first ADF Essentials application could run.

In the next chapter, we'll learn more about how to develop business services using ADF Business Components for Java.

About the Author

  • Sten E. Vesterli

    Sten E. Vesterli picked up Oracle development as his first job after graduating from the Technical University of Denmark and hasn't looked back since. He has worked with almost every development tool and server Oracle has produced in the last two decades, including Oracle ADF, JDeveloper, WebLogic, SQL Developer, Oracle Portal, BPEL, Collaboration Suite, Designer, Forms, Reports, and even Oracle Power Objects.

    He started sharing his knowledge with a conference presentation in 1997 and has given more than 100 conference presentations at Oracle OpenWorld and at ODTUG, IOUG, UKOUG, DOAG, DOUG, and other user group conferences around the world since. His presentations are highly rated by the participants, and in 2010 he received the ODTUG Best Speaker award.

    He has also written numerous articles, participated in podcasts, and written Oracle Web Applications 101,  Oracle ADF Enterprise Application Development – Made Simple, and  Developing Web Applications with Oracle ADF Essentials. You can find his blog at www.vesterli.com and follow him on Twitter as  @stenvesterli.

    Oracle has recognized Sten's skills as an expert communicator on Oracle technology by awarding him the prestigious title, Oracle ACE Director, carried by less than 100 people in the world. He is also an Oracle Fusion User Experience Advocate and sits on the Oracle Usability Advisory Board and participates in the Oracle WebLogic Partner Council.

    Based in Denmark, Sten is a partner in the Oracle consulting company Scott/Tiger, where he works as a senior principal consultant. When not writing books or presenting, he is helping customers choose the appropriate technology for their needs, teaching, mentoring, and leading development projects. In his spare time, Sten enjoys triathlon and completed his first Ironman in 2012.

    Browse publications by this author
Book Title
Unlock this book and the full library for FREE
Start free trial