Developing an Oracle ADF application with Oracle Enterprise Pack for Eclipse (OEPE)

Besides providing a tour of major components in Oracle Enterprise Pack for Eclipse, this tutorial shows you how to build a basic Oracle ADF application.

Approximately 30 minutes.

Topics

This tutorial covers the following topics:

Launching Eclipse

Setting the Workbench Perspective for an Application

Creating an ADF Application

Defining the WebLogic Server
Creating a Managed Bean
Creating JSP Pages
Using a Resource Bundle File for the Pages
Optimizing the Use of the Code Editor

Refining the Welcome Page

Running the Application

Using AppXray Dependencies

Summary

Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.

Overview

In the tutorial, you learn how to create an Oracle ADF Application using Oracle Enterprise Pack for Eclipse (OEPE), define the WebLogic Server and configure the deployment environment. Additionally you create two JSP pages and run these pages in the embedded browser. Finally, you explore the functionalities of AppXray and review the dependencies between the components of your application.

Back to Topic List

Prerequisites

Before you begin this tutorial, you should:

1.

Have access to or have installed Oracle Enterprise Pack for Eclipse. You can download it from Oracle Technology Network. Unzip to a directory of your choice, which in this tutorial is referred to as ECLIPSE_HOME.

 

2.

Have access to or have installed Oracle WebLogic Server 10.3.4. You can download it from Oracle Technology Network.

To install WebLogic, double click the .exe file to launch the Oracle Installer and install it into the directory of your choice, which in this tutorial is referred to as WEBLOGIC_HOME.

 

3.

Since you are using WLS 10.3.4 and because Weblogic Server 10.3.4 requires JDK 1.6, OEPE 11g must be launched with JDK 1.6 as well. There are two ways to do this:

  • update the system PATH variable so that JDK 1.6 is the default JDK for the OS. (i.e.: PATH=<WEBLOGIC_HOME>\jdk160_05\bin;%PATH%).
  • update the eclipse.ini with a –vm flag to specify which JDK they want Eclipse launched with.

To implement the second option, locate the directory where the WebLogic JDK was installed. (for example: <WEBLOGIC_HOME>\jdk160_21\bin) and copy the path in the clipboard.

 

4.

Locate the ECLIPSE_HOME directory and open the eclipse.ini file using notepad.

 

5.

Enter the following statement : -vm then copy the content of the clipboard.

 

6.

Save and close the eclipse.ini file.

Back to Topic List

Launching Eclipse

Now that the environment is set, you can start Eclipse. Since you've installed the complete OEPE build using the Oracle Installer, to launch the tool, perform the following steps:

1.

Start Eclipse by clicking the Start button then, All Programs --> Oracle Enterprise Pack for Eclipse --> Oracle Enterprise Pack for Eclipse.

 

2.

Eclipse starts loading up and a Workspace Launcher dialog pops up. Specify a Workspace folder for your work.

Click OK. Eclipse continues to load up.

 

3.

The Eclipse Welcome screen appears.

 

4.

Click on the Overview link within the Welcome screen and see the content.

Other topics are now accessible as Menu icons. You can try each one to see details.

 

5.

To start working, click the Workbench icon.

 

6.

The Eclipse IDE opens up.

 

7.

To redisplay the Welcome screen, from the Main menu select Help --> Welcome.

Back to Topic List

Setting the Workbench Perspective for an Application

The term Workbench refers to the desktop development environment. The Workbench aims to achieve seamless tool integration and controlled openness by providing a common paradigm for the creation, management, and navigation of workspace resources.

Each Workbench window contains one or more perspectives. A perspective defines the initial set and layout of views in the Workbench window. Within the window, each perspective shares the same set of editors. Each perspective provides a set of functionality aimed at accomplishing a specific type of task or works with specific types of resources. For example, the Java perspective combines views that you would commonly use while editing Java source files, while the Debug perspective contains the views that you would use while debugging Java programs. As you work in the Workbench, you will probably switch perspectives frequently. More than one Workbench window can exist on the desktop at any given time.

To define a perspective for a future project, perform the following steps:

1.

Click the Open Perspective icon to select the appropriate perspective for your development.

 

2.

In the list of perspectives, select the Other option to view all available perspectives.

 

3.

Review the list of possible perspectives, and select the Java EE one.

Click OK.

 

4.

The IDE updates to a new set of views and editors that are best suited to performing Java EE tasks.

 

5.

Review each of the tabs in the bottom section of the IDE. As the tutorial goes on, you get a chance to explore the content of some of the tabs.

6.

From the main menu, selecting Window --> Show View allows you to open or reopen specific views. Select the Other option.

 

7.

In the Show View dialog, expand the General node. Notice that views or editors already opened are greyed out. Select the Palette view and click OK.

Back to Topic List

Creating an Oracle ADF Application

An enterprise application project ties together one or more J2EE modules, including application client modules, EJB modules, Connector modules, or Web modules. To create a new Oracle ADF Application, perform the following steps:

1.

To start working, from the main menu select File --> New --> Other.

Notice that since you want to use the new Oracle ADF Application type of template, you could directly use the Oracle ADF Application choice, but selecting the Other option will show you what other Java EE type of application templates are usable.

 

2.

In the New dialog, expand the Java EE node and from the list of available Java EE templates, select Oracle ADF Application. This will create 2 projects, an EAR and a dependant Web Module

Click Next.

 

3.

In the New Oracle ADF Application, enter ADFFacesTutorial as the Application name. Click the New Runtime button to set WebLogic Runtime environment.

 

4.

In the New Server Runtime environment select Oracle | Oracle Weblogic Server 11gR1 PatchSet 3.

Click Next.

 

5.

In the Define a WebLogic Runtime step, click the Browse icon next to the WebLogic home field.

 

6.

In the Browse for Folder, select wlserver_10.3 corresponding to the location of your WebLogic server home directory.

Click OK.

 

7.

Back in the dialog check the Server extensions Oracle ADF runtime 11.1.1.4.0 is installed. OEPE 11g validates a WebLogic Server installation for a properly configured ADF Runtime. Using the full install should have included the Oracle ADF Runtime. (If not click the Install link and follow the steps to install it from OTN.)

Click Finish then Finish again. Eclipse starts building your application environment.

 

8.

This creates two projects, an Enterprise Application Project (EAR project in Eclipse) ADFFacesTutorial and then a Dynamic Web Project ADFFAcesTutorialWeb. Back to the Eclipse IDE, the two projects now appear in the Project Explorer.

9.

Expand the nodes of the ADFFacesTutorial project to review the default environment created for an EAR project.

 

10.

Double-click the adf-config.xml file to open it in the editor with the Source view.

 

11.

Note that the adf library adf-loc.jar has been added to your project. Open and examine the configuration file application.xml.

 

12.

Open the weblogic-application.xml. Notice the shared libraries (adf.oracle.domain).

 

13.

Click the Source tab , and notice the declared components such as listeners and libraries.

In the Project Explorer window, collapse the ADFFacesTutorial node.

 

14.

Expand the nodes of the ADFFacesTutorialWeb project to review the default environment created for a Web project.

 

15.

Double-click the WebContent | WEB-INF | web.xml node to edit the file. Notice the resources.application reference to a resource bundle file usable for internationalizing applications.

 

16.

Open the application.properties file and review the content of the bundle file.

 

17.

Open the weblogic.xml showing the Shared Libraries. All these libraries were generated when you created a new J2EE workbench.

 

18.

Scroll down and open the index.jsp page that has been created by default in your Web project. Notice that the page is referencing the bundle file.

 

19.

Collapse all the open nodes in the Project Explorer then right-click in any tab and select Close All to close all open tabs of the Editor pane.

Back to Topic List

Defining the WebLogic Server

Before starting to create your pages, you need to create a server configuration. It will be the link to the weblogic instance that will be used to run the project. To configure the WebLogic Server, perform the following steps:

1.

In the bottom pane, click the Servers tab. In the editor right-click and select New-> Server.


2.

In the Define a New Server dialog, select Oracle WebLogic Server 11gR1 PatchSet 3.

Click Next.

 

3.

WebLogic Server requires a domain directory. You can Browse to select an already existing domain or click the Create button to create a new domain either directly or by using a wizard. Select the Create Domain option.

 

4.

The Oracle JRF template is already installed, make sure it is selected. Specify adf_tutorial as the name. You could also specify a different password to override the default welcome1 one.

Click Finish. This will create a new domain in WebLogic server.

 

5.

Back to the New Server dialog, the Domain directory field is now completed.

Click Next.

6.

Select the upper node ADFFacesTutorial in the Available pane and using the Add button, shuttle the selection in the Configured pane.

click Finish.


7.

The new server appears in the server log pane. Expand the nodes to review its components.

Notice that the Server is in a Stopped state.

Back to Topic List

Creating a Managed Bean

To create a Managed bean to interact with the two JSP Pages that you will define, perform the following steps:

1.

In the ADFFacesTutorialWeb project , expand the Faces Configuration node and right-click the Managed Beans entry to select New Managed Bean from context.

 

2.

In the New Managed Bean dialog, select the Create a new Java class option.

 

3.

In the New Managed Bean Wizard, enter tutorial as the package name and LoginBean as the name, leave other options to default values.

Click Next.

 

4.

Set the Scope to session and click Next.

 

5.

The Summary reports all the properties for the bean.

Click Finish.


6.

Creating the managed bean added several entries in the Project Explorer, one is the LoginBean in the Managed Beans node. Double-click it; this will open the faces-config.xml file where the bean is referenced.

 

7.

Click the Managed Bean tab and select the loginBean. Click the Managed Bean class link.

 

8.

The LoginBean.java class opens in the java editor.

 

9.

Notice that in the Project Explorer, the LoginBean Java class is in the Java Resources | tutorial package.

 

10.

Add two String type variables for userName and password.

private String userName;
private String password;

 

11.

Use the short cut Alt + Shift + S and select the Generate Getters and Setters option from the pop up menu. (You could get the same menu doing a right-click in the editor and from context select Source --> Generate Getters and Setters).

 

12.

In the Generate Getters and Setters dialog, select the two variables you want to create getters and setters for. Select the After 'password' option for the location of the method code.

 

13.

The new class should now look like this:

14.

Click the Save All button to save your work.

Back to Topic List

Creating JSP Pages

You are now going to create 2 pages, one login page where you enter your username and password and a welcome page that displays your name being passed using the managed bean.

Back to Topic List

Creating the Login Page

To create the login JSP Page passing a variable value to a second page using the Java bean, perform the following steps:

1.

Right-click the WebContent node in the Project Explorer and select New --> JSP file from context.

 

2.

In the New JSP File dialog type login.jspx as the File name, then Next.


3.

Notice the variety of JSP templates available for JSP, JSF, and ADF development. Select different templates and see in the Preview pane which statements are generated for each option.

 

4.

Notice the JSP Templates link at the bottom right of the wizard, click on it.

 

5.

From here, you can select any template, see its content in the Preview pane and using the Edit button customize it for your own needs or using the New button create your own template. Since you are going to use an already existing one, click Cancel.

 

6.

Notice the proposed templates with one, two or three columns. In your case you are going to use the Basic (xhtml, xml syntax) one. Select it.

Click Finish and wait for the page to be created.

 

7.

The page opens in the editor.

 

8.

Notice the toolbar buttons in the menu bar allowing you to choose visualization between the Design, the Source or split views.

 

9.

Locate the Palette pane. Drag and drop it onto the upper right pane. You can easily customize the layout of the IDE.

 

10.

The palette displays all the available library components.

 

11.

Explore the content of the various libraries. Click on an item to expand it. For example the ADF Data Visualizations node shows all of the GUI components available to represent data such as Bar, Pies or Gauges.

 

12.

Notice that the last item in the Palette is the Data Palette. Expand it and see that its content is related to the available variables. Variables displayed in the Data Palette range from local Page Variables declared within the current jsp to JSF Managed Beans available to the whole application. The Data Palette enables easy navigation to variable and class declarations as well as Drag and Drop onto the page.

Back to Topic

Back to Topic List

Creating a Navigation Case and a Welcome Page 'on the Fly'

You are now going to create a navigation case that navigates to a second page. To create these two components 'on the fly', perform the following steps:

1.

In the code of the login page, delete the af:Form tags.

 

2.

In the Component Palette, open the ADF Faces library, scroll down and select the Form tag. Drag and drop it in place of the previous Form tag location using the tag drop editor facility.

 

3.

In the New Form Type check the Generate a form tag and content from data option. In the Form bean field click the browse button.

 

4.

Select the loginBean which will be used in the page.

Click OK.

 

5.

Back to the Form Type, click the Select a value button next to the Form Action field.

 

6.

In the Form action field define a navigation case on the fly. In the Select a navigation case dialog, click the button.

 

7.

In the New Navigation Case, enter login as the Outcome. In the Destination page field, click the Create a new JavaServer Page button to create a new page on the fly.

 

8.

In the New JavaServer Page dialog, type welcome.jspx as the name for the page.

Click Next to make sure the used template is the same as the one used for the login page. Click Finish.

 

9.

Back to the New Navigation Case dialog, click OK.

Click OK again.

 

10.

Back to the Form Type dialog, click Next.

 

11.

The username and password fields are already selected, click Next.

 

12.

In the Form fields, notice that both variables are rendering as Text Field. Select the password variable and using the drop-down list change the Rendering property to Password field. The same way, set the userName as TextArea.

If necessary, using the up and down arrows on the right, move one of the field so that userName appears on top.

Click Next. You could define in this new step an error message using resource bundle, but click Finish.

 

13.

In the Menu toolbar, click the appropriate button to show the design page view exposing the 2 fields and the Submit button that you just created. The page should now look like this:

 

14.

Click the Preview tab at the bottom of the Page editor to have a closer view of the rendering of the page in a Browser.

 

15.

The Project Explorer should now look like the following:

Back to Topic

Back to Topic List

Using a Resource Bundle File for the Pages

To use a resource bundle file for labels, texts and messages, perform the following steps:

1.

Return to the Design view, then click the JSF Core library in the Palette to add a loadBundle component. Drag the tag next to the f:view tag.

 

2.

In the New Load Bundle dialog click the Bind a dynamic value button next to the Base name field .

Locate the src | Resources | application file and click OK.

 

3.

In the Variable name field enter bundle.

Click Finish.

 

4.

Back in the code editor, using the split view, click the loadBundle icon . In the Log pane at the bottom, select the Properties tab. You can review and update the properties of any component using the Properties pane.

 

5.

Back to the code of the login.jspx page press the Ctrl key, then hover over resources.application and click the hyperlink.

The application.properties bundle file opens in the editor displaying the existing messages. You can define new key resources directly in the file or create new ones dynamically.

 

6.

Back to the login.jspx page, select the af:panelLabelAndMessage tag.

In the Property pane, click the Bind to a dynamic value button next to the Label.

 

7.

The Choose Binding dialog opens with the already defined binding elements (bundle and managed beans).

 

8.

Click the Resources tab to display the resources keys, then click the Add button to create a new key entry.

In the New Resource type name as Resource Key and Name: as the Resource Value.

Click OK.

 

9.

The new entry appears in the Resources.

 

10.

Click the View arrow and select Resource Values.

Click OK. The application.properties file is now populated with the new value.

 

11.

Back in the JSPX code, you can see the updated label field for the Panel Label And Message.

 

12.

Look at the Outline pane located on the right side. It gives a hierarchy view of the page tags.

 

13.

To experiment in another way to use the resource bundle file, click the application.properties tab to open the editor and add a new entry for password. Type password=Password\:

Click the Save All button to save your work.

 

14.

Back in the code of the login.jspx page, delete password in the label of the af:panelLabelAndMessage and type #{}. Within the brackets, press Ctrl + Space and select bundle from the suggested list.

Type '.' (comma) and from the JSP proposal popup, select password.

 

15.

Now select the Submit button and in the Property pane, click the Bind to a dynamic value Icon next to the Text field.


16.

In the Choose Binding dialog, click the Resources tab, then Click the New Resource + button.


In the New Resource dialog, enter submit as the Resource Key and Login as the Resource Value.


Click OK and OK again.

 

17.

Your login page should now look like the following:

 

18. Click the Save All button to save your work.

Back to Topic List

Optimizing the Use of the Code Editor

More features are usable in the code editor to improve productivity. To optimize your way of working with the code editor, perform the following steps:

1.

You can review the properties of all your tags in the Source code editor. For example select the af:form tag in the code editor to pop up its properties.

 

2.

Hover your mouse over the loginBean word. This shows the properties of the bean component.

 

3.

Move your mouse over the true property of the inputText tag and hold Ctrl + Space to launch code completion providing you with the possible code values.

 

4.

Move to the loginBean and while pressing Ctrl + Space, select the Open getUserName() method.

This selection opens the LoginBean.java class and points to the getUserName() getter method.

 

5.

Back to the code of the login.jspx page, press the Ctrl key, hover over the inputText tag and click the link.

 

6.

The inputText documentation from the afu.tld file is displayed.

 

7. Close the afu.tld tab.

Back to Topic List

Refining the Welcome Page

To add components to the welcome page for displaying the login name from the login bean, perform the following steps:

1.

Click the welcome.jspx tab and reopen the source code editor.

 

2.

From the JSF Core library, select the loadBundle component and drop it next to the f:view tag.

 


3.

In the Load Bundle dialog, click the Bind a dynamic value icon next to the Base name field.

 

4.

In the Resource Bundle Selection, expand the src | resources nodes and select application.

Click OK.

 

5.

Back in the Load Bundle dialog, type bundle as the Variable name.

Click Finish.

 

6.

In the Palette pane, open the ADF Faces library, and drag and drop the Output Text component within the af:form tag.

 

7.

In the New Output Text dialog, type welcome as the Id and click the Bind to a dynamic value icon .

 

8.

In the Choose Binding dialog, click the Resources tab and click the Add button.

 

9.

In the New Resource type welcome as Resource Key and Welcome: as Resource value.

Click OK twice.

Click Finish.

 

10.

Repeat the operation by dropping an Output Text component below the one you just created.

 

11.

In the New Output Text dialog, type username as the Id and click the Bind to a dynamic value icon .

 

 

12.

In the Choose Binding dialog, expand JSF Managed Beans | LoginBean and select userName.

Click OK.

 

13.

Back to the Output Text creation, click Finish.

 

14.

Your page should now look like the following:

 

15.

Clicking the Preview tab displays the following:

 

16.

Click the Save All button to save your work.

 

Back to Topic List

Running the Application

To run and test the application in the embedded browser, perform the following steps:

1.

In the Project Explorer, right-click the login.jspx node and select Run As --> Run on Server from context.

 

2.

In the Run On Server dialog, have the Choose an existing server option selected.

Click Finish.

 

3.

WebLogic Server starts and the Console window opens reporting the loading steps.

 

4.

The embedded browser launches and loads the login page.

 

5.

Enter a value for the Name and Password then click the Login button.

 

6.

The welcome page returns the username coming from the managed bean.

 

 

7.

Close the embedded browser window.

Back to Topic List

Using AppXray Dependencies

AppXRay is a central feature of Oracle Enterprise Pack for Eclipse designed for dependency tracking, validation, and visualization. AppXRay analyzes your project artifacts in order to understand their interdependencies and then uses this information to drive many of the core OEPE features such as code completion and validation in your source files, variable information in the Palette, data binding in the Property sheet, and much more. AppXRay also enables you to visualize the dependency relationships within a project. To use and analyze AppXray results, perform the following steps:

1.

In the Project Explorer right-click the login.jspx node and select Show AppXray Dependencies from context.

 

2.

AppXaminer opens in the Editor displaying the relationship the login page is having with other components. The numeric values indicate the number of references a component is having with another.

For instance the login.jspx page has 2 references with loginBean (username and password), 4 references with the application.properties and so on.


3.

You can expand another level.

 

4.

And keep going on expanding the nodes.

 

5.

Right-click in a node to view details. Right-click the loginBean node and select Show Reference Detail from context, which invokes a popup window displaying the detailed components involved.

 

6.

You can repeat the operation on each component.

 

7.

Right-click the application.properties node and select Open from context.

 

8.

The application.properties file opens in the editor.

You can open all components of your application navigating through the AppXaminer diagram.

 

9.

In Project Explorer, double-click the WebContent | WEB-INF | faces-config.xml to open the file in the editor.

 

10.

Click the Overview tab to visualize the application environment.

 

11.

Click the Navigation Rule tab for a graphical presentation of pages and navigation cases.

 

12.

Click the Managed Bean tab for reviewing the defined managed bean.

 

13.

Review the other tabs.

 

You've successfully performed this Eclipse overview of Oracle building an Oracle ADF application.

Back to Topic List

This tutorial gave you a basic overview of Oracle Enterprise Pack for Eclipse. Using a workbench, you created several projects, and defined the WebLogic server, , created a managed bean and some JSP pages using it, and run the application on the server.

You've learned how to:

Back to Topic List

Place the cursor over this icon to hide all screenshots.