
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.
Switch to the Connections Tab.
Figure 1: The Connections Tab on Mac OS X.
- Right click the Database and choose New Database Connection . . .
- In the Database Connection Wizard, review the information on the Welcome page and click Next.
- In the Connection name field type
HR.
- Click Next.
- On the Authentication page:
- In the Username and Password fields, type HR.
- Select Deploy Password.
- Click Next.
- On the Connection page:
- 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.
- 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’)
- Click Next.
- 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.
- Click Finish.
Creating a New Application
We’ll start building the application from scratch.
- From the File menu choose New.
-
In the General section choose
Application Workspace.

Figure 2: The Create Application Workspace Window.
- Update the Application Name to Hrapplication.
- Update the Application Package Prefix to Hrapp.
- Choose Web Application [Default] as the Application Template.
- 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.
- In the Model node right click and choose New.
- Choose Diagrams and Business Components Diagram from the gallery.
- Rename your diagram and Click OK.
-
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.
Figure 3: The Connection Tab
Showing the HR Node.
- Drag and drop the Departments and Employees table onto the diagram area.
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.
Figure 4: The Business Components Diagram.
Right-click on an empty area of the diagram and choose
Generate->Default Data Model Components for Diagram.
- Go through the wizard’s steps accepting all the default values.
In the Application Navigator expand the new HRapp node
to see the view objects and the application module
definition.
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.

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.
- Double-click on the
Employees Entity Object in the Application
Navigator to open the Entity Object Editor.
- 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.
- Go to the Validation node choose the
Salary attribute and click the
New button to create a new validation rule
- Choose RangeValidator from the Rules list.
- Type a minimum value of
0 and a maximum value of
99999.
- 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”.
- 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.
- Right-click on AppModule and choose Test.
- Accept all the defaults and click Connect.
A Java application appears, which you can use to work with your
application module.
Double-click on the
EmpDeptFkLink1 and you’ll see a simple master
detail window.
Figure 6: Swing-based Tester for Business Components.
- Browse through the various departments. Note how the
relationship is automatically managed for you by the ADF
Business Components.
- 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.
- 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.
Right-click on the ViewController node in the application navigator and choose Open Struts Page Flow Diagram.

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

Figure 8: The Data Control Palette.
- 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.
- 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.
- 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.
- 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.
Click on EmployeesView2 and
from the Drag and Drop As list choose
Read-Only Tableand drop it beneath the
navigation buttons.
Figure 9: Visual JSP Development and Data Binding.
- Go back to the page flow diagram for the struts-config.xml file, right click on the browseDepts and choose Run.
In the running application browse through the departments using the navigation buttons
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.
- Place a Data Page on the page flow diagram and rename it to /editEmp.
- Double-click the editEmp
data page to edit its HTML and add a page heading “Editing
Departments”.
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.
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.
- In the page editor select the departmentId text field and delete it.
- From the Data Control Palette
expand the EmployeesView2 and
click the DepartmnetID field.
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.
Figure 12: Drag and drop the DepartmentID Field.
- Now we need to link back from the edit mode to the view page.
- Back in the page flow diagram Create a
Forward link from the browseDepts
to editEmp.
- 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.
- Double-click on the browseDepts page to edit its JSP.
- Delete the ${Row.currencyString} tag in the page (first column of the last line).
- Expand EmployeeView2 in the Data Control Palette so you’ll
see the fields and the Operation nodes. Expand the
Operations node.
- 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.
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.
Figure 13: Linking to the Correct Record.
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.
Figure 14: Correcting the Page Flow.
Right-click on browseDepts and choose Run.
Figure 15: Running the Updated JSP Application in Safari.
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.
Figure 16: The Completed Application.
For More Information
Posted: 2004-12-6
|