Oracle ADF Faces Cookbook

3 (1 reviews total)
By Amr Gawish
  • 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
  1. Building Your ADF Faces Environment From the Ground Up

About this book

Oracle ADF is an ADF view framework that consists of over 150 Ajax-enabled JavaServer Faces (JSF) components. It is comparable to the jQuery User Interface library as it helps developers to build exciting User Interfaces for Java EE apps. Oracle ADF Faces 12c can be used to create scalable, reactive, and stunning user experiences.

This book covers the latest version of Oracle ADF Faces 12c and explains not only the basics of different ADF Faces components, but also how to use them to create a stunning looking application and improve it by using the Visualization components to enrich the user experience. The book starts with simple recipes by teaching you how to create your first ADF Faces application. It then moves on to introduce more advanced Oracle ADF components, Layouts, ADF Skinning, ADF Data Visualization components, ADF events, validation and conversion, and partial page rendering.

This book also covers different techniques to create reactive applications like Polling, Push, and the WebSocket protocol. Finally, this book also provides all the recipes you need to fine-tune the performance of ADF Faces web applications and to ensure you create your applications for reuse.

Publication date:
March 2014
Publisher
Packt
Pages
358
ISBN
9781849689229

 

Chapter 1. Building Your ADF Faces Environment From the Ground Up

In this chapter, we will prepare our development environment and install all the necessary software that we will be using throughout this book. This chapter contains the following recipes:

  • Preparing and structuring the OS for ADF and JDeveloper

  • Installing JDK

  • Exploring different options to install the database

  • Installing JDeveloper

  • Tuning JDeveloper

  • Downloading the book's Git repository

 

Introduction


Oracle Application Development Framework or ADF is the Oracle end-to-end flagship framework to help increase a developer's productivity by providing ready-to-use design patterns and best practices so that the developer needs only to concentrate his/her focus on the business logic rather than focusing on the technology behind it.

With Oracle JDeveloper as a cross-platform Integrated Development Environment (IDE), Oracle ADF and all Oracle Fusion Middleware suite products find the IDE that simplifies development and supports all development lifecycle stages.

Tip

Oracle ADF framework can also be developed with Eclipse IDE. By installing an Oracle Enterprise pack for Eclipse, you can develop ADF applications with Eclipse. For more information, refer to the official documentation at http://www.oracle.com/technetwork/developer-tools/eclipse/overview/index.html.

One of the main reasons behind ADF's fast growth is its Controller and View technology, which is famously known as Oracle ADF Faces.

ADF Faces is responsible for representing data to the end user and taking inputs back, passing data from and to the Data layer, respectively, to process.

If you are familiar with the Model-View-Controller (MVC) pattern, Oracle ADF Faces is the one that is responsible for all the Vs and Cs of the ADF application.

In this book, we will highlight our focus on the Oracle ADF Faces section of the ADF Framework, how to utilize it to our needs, and how to make the best data of it to create a beautiful user experience for the end user.

In this chapter, you will learn how to structure your development environment and how to organize and put everything in its right place. You will learn how to install your latest JDK and the options available for your database installation. You will practice how to install JDeveloper and how to tune it for your operational system, and how to change some general preferences inside JDeveloper. You will get an overview of Git and how to install the book's repository on your machine.

 

Preparing and structuring the OS for JDeveloper and ADF


It's important to understand the memory consumption of your software in order to work effectively without any trouble. If you would like to have a complete environment to work with ADF effectively, with your local machine, you might need to install JDeveloper and Oracle Database locally—if you like to work offline—which is a lot of memory consumption, not to mention when you debug and run your application against the application server, which would also have a medium to large memory footprint. So, make sure you have enough memory and processing power to start working with ADF effectively.

Getting ready

The following are considered minimum hardware requirements for your development machine:

  • Minimum 4 GB Memory (RAM)

  • Fast CPUs (for example, Intel Core i5)

  • SSD Hard drive, HDD with minimum 7200 RPM, or Hybrid HDD

    Tip

    For more information and guidance about performance and memory, check this great video by Chris Muir at http://www.youtube.com/watch?v=GXABzw7qU9g.

After making sure you have enough processing and memory power, you will still need to prepare your environment. You should always start by creating the directory structure to make sure everything goes into the right place, and to be in control especially after your project expands. It's always a good practice to organize how to reach your information effectively, after which you should start the installation process of your software.

How to do it…

In order to prepare and structure your operating system ADF, perform the following steps:

  1. Create your directory structure properly. What I usually do is start from the root directory of my user, for example, C:\Users\Amr in Windows or /Users/amr in a Nix-based OS, and start adding the structure of my development environment. So, in Windows, for instance, my workspace under the user directory looks like the following screenshot:

  2. Create a dev directory where all the development will reside.

  3. Create an apps directory, which will contain all the software starting from JDK to the middleware inside the Oracle directory.

  4. Create a myworkspaces directory inside the dev directory, which will include different workspaces for each technology—you are free here to make it as per technology or per actual project—and then in each technology you have your different applications.

    Tip

    I didn't introduce any whitespaces; this is important as whitespaces can cause too many troubles when dealing with JDeveloper and Java in general.

  5. Create different environment variables for your development environment's dev directory, apps directory, and myworkspaces directory. This extra step will make it easy when you are installing different software to reach these directories easily using the command line. You should end up with the following environment variables:

    $DEV_HOME=/Users/amr/dev
    $APPS_HOME=$DEV_HOME/apps
    $WORK_HOME=$DEV_HOME/myworkspaces
    
  6. You can do the same in Windows by simply navigating to System Properties | Advanced | Environment variables and create three variables with these names:

    DEV_HOME=C:\Users\Amr\dev
    APPS_HOME=%DEV_HOME%\apps
    WORK_HOME=%DEV_HOME%\myworkspaces
    

    Tip

    Sometimes you might not have enough security privileges to access System Environment Variables. However, you can achieve the same results by opening the command prompt and using the set command as follows:

    set DEV_HOME=C:\Users\Amr\dev
    set APPS_HOME=%DEV_HOME%\apps
    set WORK_HOME=%DEV_HOME%\myworkspaces
  7. If you have Mac or other Nix-based systems, you can achieve the previous result by changing the .bash_profile file using a text editor or any text editing tools.

    Tip

    I always prefer to use vi or vim when it comes to Nix-based systems, but you can use any text editing tool of your choice. To know more about vi or vim, check these resources at http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html & http://www.openvim.com/.

  8. You can create one if none exists by opening a terminal and entering the following command:

    vi ~/.bash_profile
    
  9. Edit the file by pressing I to enter the edit mode, and add the following entries to the end of the file:

    export DEV_HOME=/Users/Amr/dev
    export APPS_HOME=$DEV_HOME/apps
    export WORK_HOME=$DEV_HOME/myworkspaces
    

    Save by pressing Esc and then :wq

How it works…

Creating environment variables will help you to map everything accordingly, and will give you a structured development environment for your IDEs and workspaces. This will also help you in your future applications, as you will be able to locate all the information you need in one place, and you will know where you should go fast and easy.

After you finish creating your environment variables and all the directory structures, you should be able to start installing the software, and we will start with the JDK.

 

Installing JDK


Java Development Kit (JDK) is the engine that runs everything from JDeveloper to the application server. The latest version of the JDK is JDK 7u25 at the time of writing, but if you find a newer version, don't hesitate to use it instead.

How to do it…

  1. Download the latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html.

    You should download the latest JDK and it should work just fine, but you have to select the JDK suitable for your Operating System and its architecture

    Tip

    You will need an oracle account. This is also important when installing the Oracle Database and JDeveloper, so you should get one now if you don't already have one, and it's free too!

    Depending on the operating system, the installation should be straightforward, as for each operating system, there should be an installer with it, for example, for Windows an exe installer, for Mac you will have a dmg, and an rpm for Linux

  2. Change the JDK installation directory to be inside APPS_HOME.

    I chose the location to be C:\Users\amr\dev\apps\jdk\jdk7_25 (jdk 7 update 25) in Windows or /Users/amr/dev/apps/jdk/jdk7_25 in Nix-based systems

    Tip

    You will be prompted to install the public JRE (Java Runtime Environment); you can create a directory for the JRE as well under C:\Users\amr\dev\apps\jdk\jre7_25 or /Users/amr/dev/apps/jdk/ jre7_25.

  3. Create a JAVA_HOME environment variable, and update the PATH environment variable to look at the bin folder inside our jdk7_25 directory. This will help you greatly if you use the Java command line often.

  4. If you are using Windows, you should add the following environment variable:

    JAVA_HOME=%APPS_HOME%\jdk\jdk7_25
    

    You should change the PATH environment variable to the following:

    PATH=%JAVA_HOME%\bin;
    

    Tip

    Alternatively, you can achieve the same result as previous by opening the command prompt without going to your environment variable settings and using the set command as set PATH=%JAVA_HOME%\bin;%PATH%.

    Make sure you put %JAVA_HOME%\bin inside PATH and not %JAVA_HOME% as we want the path to reference all the Java executable files such as java and javac

    Tip

    I put it in the front because some software, when installed, can edit this and put it in the end without inserting a semicolon at the start. So, it's safer to put it in the front of the PATH environment variable.

  5. If you are using Mac or any other Nix-based system, you should edit the .bash_profile file to be the following:

    export JAVA_HOME=$APPS_HOME/jdk/jdk7_25
    export PATH=$JAVA_HOME/bin:$PATH
    

    Notice that in Nix-based systems editing a .bash_profile is little bit different as the separator is a colon and not a semicolon

How it works…

Installing the JDK is the main part. JDeveloper runs on top of the Java Virtual Machine (JVM), which requires the JDK installed. The application server also uses the JDK to run.

Defining environment variables such as JAVA_HOME and putting them inside the PATH variable is crucial as we might need to start applications using the command line and these variables will become handy during such circumstances. Also, we will need this in order to start the installer of JDeveloper after installing the database.

Now that you have finished the installation of JDK, close any terminals (command prompts) opened and start installing the database.

 

Exploring different options to install the database


Almost all enterprise applications have a backend data layer that contains one or more Database Management Systems (DBMS), and since ADF is an enterprise-enabled framework, ADF is no exception to this rule.

ADF can work with any database as long as there is a Java Data Base Connectivity (JDBC) driver.

Users are encouraged to install a database if they want to follow all the recipes to the letter through all chapters of this book.

Getting ready

ADF works best with the Oracle Database, but as mentioned before it can work with any other DBMS, such as MySQL, PostgreSQL, or MSSQL. For the purpose of this book, you should install the Oracle Database, which comes in two flavors: Oracle Database Standard edition and Oracle Database XE (Express Edition).

Tip

There is also an Oracle Database Enterprise edition, which has all the Standard Edition features plus management packs for highly critical performance such as for databases that are used in banks, which is outside the scope of this book.

Oracle XE is a version of Oracle Database that is easy to use and install; however, it only supports Windows 32-bit and Linux 64-bit versions. You can head over to http://www.oracle.com/technetwork/products/express-edition/downloads/index.html and install it if your operating system is one of the supported operating systems. If it isn't, you should install the Oracle Database Standard Edition from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html.

How to do it…

Depending on your operating system, you can know what kind of options you have:

  • Mac users: You have only one option, and that is to have a virtual machine with Linux or Windows that hosts the database. Oracle provides multiple prebuilt Virtual Machines that you can install from http://www.oracle.com/technetwork/community/developer-vm/index.html.

  • Linux users: Most of the Linux operating systems are 64-bit; if that is your case, then you are free to install either Oracle Database 12c or Oracle XE 11g. Other than that, you have to install Oracle Database 12c, or you can have a Virtual Machine with the database inside.

  • Windows users: You can install Oracle XE 11g if your operating system is either 32-bit or 64-bit—you can use the database in its 32-bit mode; however, if you want to run the database on a 64-bit architecture, you can install Oracle Database 12c or you can have a Virtual Machine with the database inside.

How it works…

Installing the database will provide you with the data that your application will need to display, edit, add, and delete; one example database schema that is installed by default and that we will use in this book is the HR schema.

If you installed Oracle Database Standard edition, you should create at least one instance for you to work with.

There's more…

Make sure after installing your database that you can connect to it properly, and while the HR schema will be be installed with your database, it'll be locked by default.

In order to unlock the HR schema, log in with your system or sys user and execute the following command:

ALTER USER HR IDENTIFIED BY PASSWORD ACCOUNT UNLOCK;

This command will alter the HR schema and set the password to PASSWORD. You are free to change the password by changing the PASSWORD keyword in the previous command to whatever you like.

 

Installing JDeveloper


Now to the fun part that is installing your IDE. JDeveloper is a great IDE for Java, but it is the de facto IDE for ADF and Oracle Middleware products.

JDeveloper comes in two flavors: Studio edition and Java edition. If you are not planning to work with ADF in your JDeveloper, you can install Java edition; otherwise, Studio edition is the best when it comes to ADF development.

There are 5 installation options for JDeveloper:

  • Windows 64 bit

  • Windows 32 bit

  • Linux 64 bit

  • Linux 32 bit

  • Generic

All installation options come with an embedded JDK except for the generic option, for which you need to preinstall JDK.

You can notice that there is no Mac version, but generic can work with any operating system.

In this recipe, we will download the generic installation option for the JDeveloper Studio edition and we will install it.

How to do it…

To install JDeveloper, perform the following steps:

  1. Go to http://www.oracle.com/technetwork/developer-tools/jdev/downloads/index.html and download the latest JDeveloper (currently 12.1.2.0.0). Make sure you accept the agreement and pick the generic version from the drop-down menu.

  2. After your download is complete, open your command prompt or terminal and change the directory—using the cd command—to the directory that contains the .jar file you just downloaded, and then execute the following command line:

    java –jar jdev_suite_121200.jar
    

    Note that you can execute the java command directly because you added the %JAVA_HOME% or $JAVA_HOME\bin directory inside the PATH environment variable, and this command basically says, start a Java application from the JAR file provided.

    Tip

    There are a couple of other arguments you can add to the previous command line such as -Djava.io.tmpdir=/path/to/tmpdir.

    The previous argument uses another temp directory instead of the Java default one. If you don't have space in your system directory, you can also control the memory footprint of the Java program by adding the –xmX and –xmS arguments as well.

  3. After executing this command, you should be able to see the JDeveloper installer screen as shown in the following screenshot:

  4. When you are prompted to enter your Oracle Home location you should choose C:\Users\<your_name>\dev\apps\oracle\Middleware\Oracle_Home.

    If you have other middleware versions, you should install 12c on a different middleware directory, for example, C:\Users\<your_name>\dev\apps\oracle\Middleware12c\Oracle_Home

  5. If you followed everything right and launched the JAR file with Java 7, the next step (prerequisites check) should pass without a problem. Click on Next and have a look at the summary of what will be installed by JDeveloper. Click on Install and let it install your favorite IDE that you will use during this book.

  6. After a couple of minutes you should feel good as your JDeveloper is ready to go. Click on Finish Installation without opening JDeveloper and click on Finish to close your installer.

How it works…

When you executed the Java command, you started the JDeveloper installation process. Since we downloaded the Studio Edition, it'll ask you about your middleware home directory since it expects you to have multiple middleware products installed.

When you choose a middleware home directory, make sure not to pick up any existing middleware homes as different versions' installation on the same directory can cause lots of troubles.

There's more…

Don't be tempted to open JDeveloper just yet; we need to do a few things before starting JDeveloper.

First we need to create a new environment variable, which will point to the root directory of all our ADF applications; the environment variable needs to be named JDEV_USER_HOME.

You can set the environment variable in Windows to be under the WORK_HOME directory by executing the following command in the command prompt:

set JDEV_USER_HOME = %WORK_HOME%\adf

For the Nix-based version the environment variable can be set by using the following command:

export JDEV_USER_HOME = $WORK_HOME/adf

JDEV_USER_HOME is a reserved name that JDeveloper looks for before starting; if it's defined, JDeveloper will automatically create new applications in the directory.

Tip

When setting JDEV_USER_HOME, all other JDeveloper versions you have in your operating system will be affected as well. If you want to still work with other older JDeveloper versions, make sure you don't create it as an environment variable and rather create a small Windows or Nix batch file to start JDeveloper which sets this variable for the session lifetime only. Check the Git repository, for example, of batch files at https://github.com/agawish/ADF-Faces-Cookbook/tree/master/Chapter%201.

After setting the variable, we need to tune some configuration of JDeveloper before starting it and we are going to use the next recipe for that.

 

Tuning JDeveloper


JDeveloper can work without tuning, but tuning is worth looking at for when you are looking at big enterprise applications that have many projects with source control and more than one team member.

How to do it…

In order to tune JDeveloper, perform the following steps:

  1. Open your Oracle Home directory that we set up when installing JDeveloper, and navigate to %MIDDLEWARE_HOME% | Oracle_Home | jdeveloper. There are two files that you want to change: the first file is ide.conf located under ide\bin\ide.conf.

  2. Open the file using your favorite text editor and locate the following lines:

    AddVMOption –Xms
    AddVMOption -Xmx
    

    You may want to increase these values if they are very low, for example, if you have more than 4 GB of RAM, you should set it to 1 GB each as shown in the following code:

    AddVMOption –Xms1024M
    AddVMOption –Xmx1024M
    
  3. Save and close the file.

  4. Open the jdev\bin\jdev.conf path under the jdeveloper directory.

  5. Add the following entries at the end of the file:

    # optimize the JVM for strings / text editing
    AddVMOption -XX:+UseStringCache
    AddVMOption -XX:+OptimizeStringConcat
    AddVMOption -XX:+UseCompressedStrings
    
    # if on a 64-bit system, but using less than 32 GB RAM, this reduces object pointer memory size
    AddVMOption -XX:+UseCompressedOops
    
    # use an aggressive garbage collector (constant small collections)
    AddVMOption -XX:+AggressiveOpts
    
    # for multi-core machines, use multiple threads to create objects and reduce pause times
    AddVMOption -XX:+UseConcMarkSweepGC
    AddVMOption -XX:+UseGCOverheadLimit

    These settings ensure that your JVM is optimized for your operating system. Also note that some of them are tailored depending on your Operating System architecture. So, don't just copy and paste them. Check what can apply and add accordingly.

    Tip

    If you started JDeveloper and faced some troubles, try reducing the amount of memory assigned with Xms and Xmx and start it again.

  6. Start JDeveloper now. You have tuned it for your operating system, and now it's time to change some general preferences of JDeveloper itself. So, let's start by starting your JDeveloper as shown in the following screenshot:

  7. When you get a prompt that asks which mode you want to choose, leave the default value of the Studio Developer (All Features) option and click on OK.

    Tip

    If this is not your first JDeveloper, you will also be prompted to migrate from the older JDeveloper versions. If you are planning to still use the old JDeveloper version and don't want to migrate your project, click on No; otherwise, click on Yes.

  8. Go to the JDeveloper preferences by navigating to Tools toolbar | Preferences.

  9. Change the following inside preferences:

    • Environment: Change the Encoding to UTF-8

    • Navigate to Code Editor | Line Gutter and enable Show Line Numbers

    • Navigate to Run | Weblogic and click on Load Extension and enable FastSwap

  10. Enable external tools by navigating to Tools | External Tools and making sure every item is selected and then clicking on OK.

How it works…

JDeveloper, like all IDEs, has configuration files that can be used to tune it to work without having memory problems. These configuration files are ide.conf and jdev.conf.

The first file controls the main JVM memory parameters that the JDeveloper thread will start using, and jdev.conf is used to add any additional configuration to the JDeveloper in order to enhance its performance with multicore processors or 64-bit architecture systems.

After that, we started JDeveloper for the first time and you were prompted to select a Role or Mode. Each role is tailored towards a specific behavior.

There are 5 roles you can choose from:

  • Studio Developer (All Features): This includes all the features of the IDE

  • Customization Developer: This allows the developer to create customizable applications using the Oracle Metadata Service (MDS) framework

  • Database Edition: This gives access to the core database development tools

  • Java EE Edition: This includes features of core Java EE development only

  • Java Edition: This includes only features of core Java development

After starting JDeveloper, we also need to tune the JDeveloper preferences themselves. This is different since you have control over them from the JDeveloper IDE. So, you may want to change them while you are working. Secondly, it doesn't relate to the JVM thread but it's totally an application-specific property.

Doing these changes to the JDeveloper preferences can increase your performance time by preventing you from facing some problems with encoding and other stuff when you are working with other team members or a multilanguage application.

See also

If you want to explore more properties that you can tweak with JDeveloper beyond the scope of this book, check the ADF EMG discussion at https://groups.google.com/forum/#!topic/adf-methodology/g3q8TgHtsbk.

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. You can also download the files from GitHub at https://github.com/agawish/ADF-Faces-Cookbook/archive/master.zip. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

 

Downloading the book's Git repository


In order to keep your code organized, especially with bigger numbers of team members, you need to have a source control system. There are all sorts of version control systems starting from CVS passing by the famous SVN to the new distributed version control systems such as Git and Mercurial, which offer a different model, particularly for offline usage.

Git is a free and open source distributed version control system; you can learn about it very easily at http://git-scm.com/documentation.

Git also has a tiny footprint with lightning-fast performance. It outclasses SVN, CVS, Perforce, and ClearCase.

You don't have to follow the trend in here, just use what you and your team feel comfortable with.

I chose Git as a repository to have all the example applications used in this book.

You can check the book's repository content at https://github.com/agawish/ADF-Faces-Cookbook and start navigating through the code samples and files for each chapter. You can also download the whole thing and you can contribute if you find any bug or want to make some edits.

The great thing about JDeveloper, especially 12c, is that it comes with Git by default. So, you don't need to install anything. One thing you need to know is that terminology is quite different from SVN.

How to do it…

  1. Clone the Git project by navigating to Team | Git and clicking on the Clone menu.

    The command is named Clone because of the distribution nature of Git, as you really clone the project locally on your machine

    Tip

    Clone is the same as Checkout in SVN and CVS.

  2. Leave the name as original, add https://github.com/agawish/ADF-Faces-Cookbook.git to the repository URL, enter your Github username and password, and click on Next.

    If you entered your information correctly, you should see the branch master in the Include list. This is another great feature. When you have a stable project, the main code base should be in the master branch, but if you decided to implement other features, you may want to create a new branch and migrate it to the master branch when you finish.

  3. Click on Next to choose the cloned repository directory, a name of your repository, and to check which branch you want.

  4. Click on Finish after you finish and you will have the entire book's Git repository locally.

  5. Click on No when you are prompted to create a project out of the Git repository. However, you don't want to choose that option since the repository contains multiple applications.

  6. Access specific applications from the filesystem.

How it works…

JDeveloper uses the concept of plugins or extensions. With each extension comes a set of features that can manipulate your project in a certain way.

With Git you get all the advantages of having a distributed version control system inside your IDE. You can commit your code within JDeveloper without the need to leave JDeveloper, which will increase your productivity and decrease the time you need to spend using third-party applications to manage your project.

See also…

To know more about Git, check the original website at http://git-scm.com/. Also, check these references at http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide for a practical definitive guide to getting started with Git.

About the Author

  • Amr Gawish

    Amr Gawish began his career at the age of 18, working as a web designer before entering college. He is very passionate about technology and always tries to push the limits of the technologies he uses.

    He completed his bachelor's degree in Math and Computer Sciences from Al-Azhar University in Egypt and is currently persuing his master's at the University of Liverpool. He is currently employed as an Oracle Fusion Middleware consultant and is certified in Java SE 7, Oracle ADF, WebCenter Portal, and Oracle SOA Suite. He has worked with all these products and the rest of the Oracle middleware stack for more than six years.

    He has also gained a fair amount of experience in various other topics such as Gamification, Scala programming, and Akka and is currently working on microcontroller programming with Raspberry Pi and Arduino and robotics.

    You can learn more about him by visiting his website, www.amr-gawish.com, or follow him on Twitter (@agawish).

    He is currently working with infoMENTUM (www.infomentum.com), which is an Oracle Platinum Partner; a leading company in Oracle Fusion Middleware; and the first company to specialize in WebCenter (both content and portal), Oracle SOA, ADF, and Java in the EMEA region.

    Browse publications by this author

Latest Reviews

(1 reviews total)
Poco documentado, necesita referencias externas
Book Title
Access this book, plus 7,500 other titles for FREE
Access now