Apple Developer Connection
Advanced Search
Member Login Log In | Not a Member? Contact ADC

Using Oracle JDeveloper on Mac OS X

Oracle JDeveloper 10g is an integrated development environment (IDE) for building applications and Web services using the latest industry standards for Java, XML, and SQL. It provides a single, highly integrated IDE that is developer-friendly, with a consistent interface and development experience. Oracle JDeveloper 10g is already an increasingly popular choice for Java development on Mac OS X, and starting with JDeveloper 10g version 10.1.2, production releases are fully certified and supported on the Mac OS X platform.

Oracle JDeveloper simplifies the way you build Java applications that interact with databases. This article introduces you to JDeveloper 10g and then provides a tutorial to get you started. In the tutorial, you build a simple application that displays information about departments and employees from database tables, using both a Web HTML interface and a Swing-based interface, and you lthen earn how to manipulate the data.

Introducing Oracle JDeveloper on Mac OS X

Complete and integrated, Oracle JDeveloper 10g supports every step of the development life cycle, including modeling, coding, debugging, testing, profiling, tuning, and deploying applications. All these tasks are done in a single IDE using a set of integrated features.

Oracle JDeveloper 10g focuses on Java application development using J2EE, J2SE, or J2ME, while also enabling XML-based application development with features such as the XML Schema Modeler, XML Code Insight, and the XML Tag Property Inspector. To complete the developer's toolbox, Oracle JDeveloper 10g provides a full development and modeling environment for building database objects and stored procedures.

Supports Multiple Development Styles

The goal of Oracle JDeveloper 10g is to make J2EE development simpler and more accessible. To achieve this goal, Oracle JDeveloper 10g offers a visual and declarative approach to J2EE development, an approach that serves as an excellent match with Mac OS X. Development is simplified even further by the Oracle Application Development Framework (Oracle ADF), a J2EE development framework that implements design patterns and eliminates infrastructure coding.

Oracle JDeveloper 10g is unique in that developers get the same productive development experience regardless of the technology stack involved. For example, you can choose to implement a persistence layer using simple Java classes, EJB, Oracle Application Server TopLink 10g, Oracle ADF Business Components, or Web services. Regardless of the chosen technology, Oracle JDeveloper 10g provides a declarative means of creating this layer, as well as drag-and-drop mechanisms to bind user interface components to any of these implementations.

Being 100% Java, Oracle JDeveloper 10g is a cross-platform IDE that lets you choose your development platform: Applications developed with Oracle JDeveloper 10g work with any data source and can be deployed on WebObjects or any other J2EE-compatible application server.

Standard, Open, and Extensible

Oracle JDeveloper 10g enables developers to use the latest industry standards to develop applications that can operate across multiple hardware and software platforms. As described above, applications built with Oracle JDeveloper 10g can be deployed to any J2EE-compliant server and access any JDBC-compliant database.

Oracle JDeveloper 10g embraces popular open-source frameworks and tools, providing built-in features for Struts, Ant, JUnit, and CVS. This integration enables developers to use these open source tools to streamline their development process.

Building a Sample Application with Oracle JDeveloper on Mac OS X

You can download JDeveloper 10g (10.1.2 or later) from Oracle Technology Network (OTN). All downloads are free under the terms of the OTN license.

This How-To requires an Oracle Database installation; you can download Oracle Database 10g from OTN.

When you have JDeveloper installed, you can then begin working with this tutorial.

First, you need to set-up a connection to your database.

NOTE: We are using the HR sample user that you get with a default installation of the Oracle Database. You might need to unlock the user after the default installation using the following command:

 ALTER USER "HR"  IDENTIFIED BY "hr"  ACCOUNT UNLOCK; 

If you are encountering any problems with this step you might want to ask your database administrator for help.

  1. Switch to the Connections Tab.

    The Connections Tab on Mac OS X

    Figure 1: The Connections Tab on Mac OS X.

  2. Right click the Database and choose New Database Connection . . .
  3. In the Database Connection Wizard, review the information on the Welcome page and click Next.
  4. In the Connection name field type HR.
  5. Click Next.
  6. On the Authentication page:
    1. In the Username and Password fields, type HR.
    2. Select Deploy Password.
    3. Click Next.
  7. On the Connection page:
    1. In the Host name field, type the name (or IP address) of the computer where the database is located.  The default ‘localhost’ should work if the database is installed on your local PC.
    2. In the SID and Port fields, type the information for this connection. If you do not know these values, check with your database administrator. (The default ‘SID’ is ‘ORCL’ and the default port is ‘1521’)
    3. Click Next.
  8. Click Test Connection. If the database is available and the connection details are correct, you will see the message "Success!”. If an error occurs, verify the settings with your database administrator.
  9. Click Finish.

Creating a New Application

We’ll start building the application from scratch.

  1. From the File menu choose New.
  2. In the General section choose Application Workspace.

    The Create Application
      Workspace Window

    Figure 2: The Create Application Workspace Window.

  3. Update the Application Name to Hrapplication.
  4. Update the Application Package Prefix to Hrapp.
  5. Choose Web Application [Default] as the Application Template.
  6. Click OK.

Modeling Oracle ADF Business Components

For the Business Services layer we want to have Java objects that can interact with the database. We’ll use Oracle ADF Business Components for this layer. Oracle ADF Business Components is a framework that manages every aspect of interaction with your database, including tasks such as Object/Relational Mapping, Persistence, Transaction Management and Connection Pooling.

You can create Oracle ADF Business Components directly from a wizard, but will go through a UML modeler to get a better picture of what we are doing.

  1. In the Model node right click and choose New.
  2. Choose Diagrams and Business Components Diagram from the gallery.
  3. Rename your diagram and Click OK.
  4. Make sure that you can see the Connection Tab and expand the HR node so you’ll be able to see the various Tables in this schema.

    The Connection Tab
        Showing the HR Node

    Figure 3: The Connection Tab Showing the HR Node.

  5. Drag and drop the Departments and Employees table onto the diagram area.
  6. The dialog window lets you choose what to create from the tables. If you switch to see the All Technologies instead of just the Project Technologies you’ll see that you can create Enterprise JavaBeans or simple Java Objects from the tables in the same way. But for this project choose the Business Components Entity Objects and click OK.

    The diagram in Figure 4 shows you the two objects, their attributes and the relationships between them.

    The Business Components Diagram

    Figure 4: The Business Components Diagram.

  7. Right-click on an empty area of the diagram and choose Generate->Default Data Model Components for Diagram.

  8. Go through the wizard’s steps accepting all the default values.
  9. In the Application Navigator expand the new HRapp node to see the view objects and the application module definition.

  10. Your Model project should now have a few new entities and views with the relationships defined between them. You can see the actual Java files that were generated in the Structure Window when you select items in the Application Navigator.

    The Application
        Navigator window

    Figure 5: The Application Navigator window.

Adding Simple Validation

Oracle ADF Business Components provide a very easy way to add simple validation rules to objects. Now let's add a validation that will make sure the value of an employee salary is inside a specific range.

  1. Double-click on the Employees Entity Object in the Application Navigator to open the Entity Object Editor.
  2. Go to the Java node, here you can tell JDeveloper to generate the Java files for each of the components, this can be helpful when you want to override any of the methods that the objects provide. For example you can indicate that you want to generate the setter and getter method and then you can add business logic to the setSalary method. Since our validation is a simple one we can use meta-data to define it instead of code.
  3. Go to the Validation node choose the Salary attribute and click the New button to create a new validation rule
  4. Choose RangeValidator from the Rules list.
  5. Type a minimum value of 0 and a maximum value of 99999.
  6. Type in an Error message that will be displayed in case the value is not valid something like “Salary must be between 0 and 99,999”.
  7. Click OK to close the dialog.

Testing the Business Service Layer

Now that you finished defining the Oracle ADF Business Components layer it would be nice to test it and see that all the definitions you made actually work. This is easy to do using the Application Module tester to create a simple Swing-based graphical user interface.

  1. Right-click on AppModule and choose Test.
  2. Accept all the defaults and click Connect.
  3. A Java application appears, which you can use to work with your application module.

  4. Double-click on the EmpDeptFkLink1 and you’ll see a simple master detail window.

    The Master Detail
            Window

    Figure 6: Swing-based Tester for Business Components.

  5. Browse through the various departments. Note how the relationship is automatically managed for you by the ADF Business Components.
  6. Try to update the Salary field to “-8” and you’ll notice the error message you specify when you try to leave the field. Correct the value to a valid one.
  7. Exit the application and save all your work.

In this section we developed the Business Services layer and ran a simple client server application to test it.

Next we’ll work on another type of user interface for the same Business Service—an HTML based user interface

Creating a Data-bound JSP Application

In this section we’ll create a simple application that displays the data exposed by the Oracle ADF Business Components business services layer. The application will enable users to browse departments.

We’ll use Struts to control the flow between two JSP pages that bind to our business services via the Model layer. Oracle ADF delivers a very easy way to bind the Control and View Layers to Business Services of any type through its Model abstraction layer. This innovative architecture is the base for JSR-227.

Creating a Departments Browser

First we want to let the user browse the departments.

To do this we’ll create a Struts page flow and add some data pages and define the flow between them using Struts.

  1. Right-click on the ViewController node in the application navigator and choose Open Struts Page Flow Diagram.

    The View Controller
               in the Application Navigator

    Figure 7: Visual Struts Page Flow Editing.

  2. From the component palette choose a Data Page, click to place it in the diagram area and call it /browseDepts.
  3. Double-click on browseDepts to edit the page, accept the default JSP page name. And click OK.
  4. You are now in the Visual JSP editor; Add a Heading to your page Browsing Departments and format it.
  5. Now we’ll use the Data Control Palette to add database interaction to this page. Make sure the palette is viewable Ctrl+Shift+D.

    The Data Control Palette

    Figure 8: The Data Control Palette.

  6. Locate your cursor on the Departmentsview1 object. At the bottom of the Data Control Palette you’ll see a Drag and Drop As list. Choose Read Only Form from the list and drag the on to the page. This creates a form with an HTML table that will display data from the Departments data object.
  7. Choose Departmentsview1 object in the Data Control Palette and from the Drag and Drop As list choose Navigation Buttons and drop it inside the form that was created just after the HTML table. This will create a set of buttons that will let you scroll through your data.
  8. Now we’ll add the option to see the employees in each department. One of the benefits of Oracle ADF Business Components is the automatic management of master-detail relationships.
  9. In the Data Control Palette expand Departmentsview1 node so you’ll be able to see the fields of this table, right after the field you’ll see the EmployeesView2.
  10. Click on EmployeesView2 and from the Drag and Drop As list choose Read-Only Tableand drop it beneath the navigation buttons.

    Dropping the Table in Place.

    Figure 9: Visual JSP Development and Data Binding.

  11. Go back to the page flow diagram for the struts-config.xml file, right click on the browseDepts and choose Run.
  12. In the running application browse through the departments using the navigation buttons

    Displaying the Fields in Safari

    Figure 10: Running the JSP Application in Safari.

Notice that you didn’t manually write any code to bind your JSP page to your data model. Oracle ADF takes care of binding the data to the controller automatically through the use of special data actions connected to the data pages.

Another thing to note is the formatting and heading of the Hiredate column in the employees details, the definitions you made in the model layer are reflected in the HTML user interface.

Editing An Employee

The next step is to allow the user to choose a specific employee and edit its data. To do this we’ll create a new data page.

  1. Place a Data Page on the page flow diagram and rename it to /editEmp.
  2. Double-click the editEmp data page to edit its HTML and add a page heading “Editing Departments”.
  3. From the Data Control Palette choose the EmployeesView2 object and from the Drop As list choose Input Form. Drag and Drop the EmployeesView2 object onto the HTML page.

    Dropping the EmployeesView2 Object

    Figure 11: Dropping the EmployeesView2 Object.

Until now we used the drag and drop data binding from the model to the JSP only for complete records, but this operation can also be done at the item level. For example let’s make sure that users can’t update the department ID of an employee by replacing that text field with a display field.

  1. In the page editor select the departmentId text field and delete it.
  2. From the Data Control Palette expand the EmployeesView2 and click the DepartmnetID field.
  3. From the Drag and Drop As list choose Value and drag and drop it to the empty space where the text field used to be.

    Drag and drop the DepartmentID Field

    Figure 12: Drag and drop the DepartmentID Field.

  4. Now we need to link back from the edit mode to the view page.
  5. Back in the page flow diagram Create a Forward link from the browseDepts to editEmp.
  6. Create a reverse Forward link from editEmp to browseDepts and rename it from Success to Submit (this can be done in the property inspector).

Next we’ll enable the user to select a specific employee from the list shown for each department. We’ll use a built in operation that the data controller offers us to select a specific record in a multi record set.

  1. Double-click on the browseDepts page to edit its JSP.
  2. Delete the ${Row.currencyString} tag in the page (first column of the last line).
  3. Expand EmployeeView2 in the Data Control Palette so you’ll see the fields and the Operation nodes. Expand the Operations node.
  4. Select the setCurrnetRowWithKey (String) operation and from the Drag and Drop As list choose Find Row Link and drop it into the empty cell you created. This is a special action provided by Oracle ADF Business Components.
  5. Right-click on the Select link that was created and choose Edit Tag. Change the tag Text to Edit. Note the name of the event that the URL directs to—it uses the supplied setCurrnetRowWithKey event.

    Linking to the Correct Record

    Figure 13: Linking to the Correct Record.

  6. Back in the page flow diagram, rename the browseDepts to editEmp forward link to setCurrnetRowWithKey. This directs Struts where to go to when this event is invoked.

    Correcting the Page Flow

    Figure 14: Correcting the Page Flow.

  7. Right-click on browseDepts and choose Run.

    Displaying the Application in Safari

    Figure 15: Running the Updated JSP Application in Safari.

  8. Browse the departments, choose one of the employees and hit the update link to try and update its data. Try to insert an invalid value for the Salary field (like -9) and watch the error message we defined in the data model show up.

    The Completed Application

    Figure 16: The Completed Application.

For More Information

Posted: 2004-12-6

Copyright © 2004 Oracle Corporation. All rights reserved. Used by permission.