http://www.developer.com/java/ent/article.php/3492406/Rapid-J2EE-Development-with-Oracle-ADF.htm
In a push toward simplified J2EE, vendors have been unveiling rapid application development (RAD) tools at a furious pace. Today, for example, most integrated development environments (IDEs) provide wizards to generate the mundane and repetitive framework code necessary when building Model-View-Controller (MVC) applications. A good framework provides an easy, consistent (and preferably declarative) way to configure application components together. That framework should also enforce a 'clean seperation of concerns' that will enable you to switch the implementation for an individual layer without affecting the rest of the application. The Oracle Application Development Framework (ADF) is based upon J2EE design patterns, features from other proven frameworks such as Struts, and concepts borrowed from its own previous framework, Business Components for Java (BC4J). The goal of ADF is to conceal the complexities of J2EE, enabling developers to focus on business logic. This article demonstrates how the ADF framework can be utilized to design a Web-based application. You will use the JDeveloper 10g IDE from Oracle. You can download a free version of it here. I'm also using the popular, open-source MySQL database that can be downloaded here. If you prefer to use Oracle's own database, the adjustments that you will need to make should be trivial. In an effort to keep things simple, I want to avoid a detailed discussion of ADF. There are a number of existing demos and articles at the JDeveloper site. However, a high-level explanation of ADF components, and how they fit into the MVC architecture, is in order. An ADF Entity object represents a business entity. This usually translates to a row of data in a table, and each Entity attribute represents a column in that table. In ADF, an Entity handles other tasks, such as business validation and format masking. In most cases, the model is the most logical place to address these concerns because it will enable maximum reuse. Validations, predicated by business requirements, are likely to be relevant no matter how the model is used. For example, verifying that an employee is always assigned to one and only one department will not change if the application were converted from a Web application to a Swing application. ADF will propagate these validations and formats to the controller and view, alleviating the need for you to address these issues elsewhere. An ADF View object exposes an Entity object to users of the application. An Entity may be accessed in numerous places, but the context in which it is used will vary. Filtering, sorting, and object relationships can be established by a view object, ensuring that the model is represented in a way that makes the most sense. The ADF Application Module bundles together View components, while providing access to your business services layer, which might use technologies such as EJB to manage your database. The Application Module provides ADF Views with transaction support, and other important data-centric services. Nothing in your model should dictate a particular view technology. An Application Module can serve as the foundation for a Swing or Struts Web application. If developing a thick client application, Swing components might communicate directly with the application module. When developing a Web-based application, your application will use a clearly defined controller to manage model-view interaction. In previous releases, ADF provided its own controller. That controller has since been replaced in favor of Struts. Struts uses an XML file, called struts-config.xml, to handle application requests and dispatch them to designated request handlers. Experienced Struts developers will appreciate the ability to leverage this existing knowledge. JDeveloper makes it easy to visually design pages using JSP and JSTL. ADF also provides its own view framework, called UIX, that offers a set of HTML widgets for generating quick and consistent-looking view pages. You will be using UIX in this demonstration. UIX components will become the foundation for Oracle's JSF (JavaServer Faces) standard implementation in future releases. The application you will build allows employees to reserve conference rooms for work-related meetings. As I mentioned earlier, a MySQL database is used to create two tables, conference_rooms and room_reservations. The DDL to create these tables is listed below. Start JDeveloper if you have not already done so. On the left, you will see the Applications-Navigator. Click the Connections tab to establish a connection to your MySQL database. Before doing this, however, it is necessary to make the MySQL JDBC driver available to JDeveloper and the embedded OC4J server you will use to run the application. You can do this by dropping the driver .jar file into the j2ee\home\applib directory of your JDeveloper home (ex. C:\jdev\j2ee\home\applib). Once complete, perform the following steps in the Applications-Navigator: To create an application in JDeveloper, right-click the Applications tab in the Applications-Navigator. Select New Application Workspace, and then type 'RoomReservations' for the Application Name. Leave the Application Template set to 'Web Application [Default]'. These actions will create a new application based upon a template that contains two folders: 'Model' and 'ViewController'. As their names suggest, they will contain the model of your MVC application, and the Struts controller and presentation pages respectively. First, you need to create two ADF Entity objects, based upon your MySQL tables. The next wizard screen asks you to establish a database connection to obtain the schema objects. You've created a Entity object entitled 'ConferenceRooms' in your model. All very straightforward. You need a second object representing the room_reservations table. Using the previous steps as a guide, create the RoomReservations model. When you reach the Attribute Settings screen, designate reservationId as the primary key. Now that you have your entities, you need View Objects to expose them to the rest of the application. As you'll recall, an ADF View exposes Entity objects to the rest of the application. A single ADF Entity may require several View objects in non-trivial applications. Repeat the previous steps to create RoomReservationsView to front your relevant ADF Entity, RoomReservations. This time, however, stop when the wizard displays the View SQL generated by the ADF framework. You would like to present users with a master-detail view of rooms and current reservations. Tools such as Oracle Forms provide built-in support for such features. However, support for master-detail forms has been lacking in Web development frameworks. Luckily, the ADF framework makes it easy. By following these next steps, you will establish a link between your Views to allow ADF to co-ordinate activity between them. There is but one piece remaining for your application's model: an Application Module to tie the 'M' in your MVC application to the business services layer. Model in the JDeveloper Application Navigator At this point, you've not committed to a particular view technology. RoomReservationsAppModule could easily serve as the basis for a Swing application. Instead, you will create a Web-based application. ADF utilizes the Struts framework to implement an application controller. As for the view, you are not really limited here. However, JDeveloper provides numerous features to visually edit JSP (JavaServer Pages) or UIX pages. YOu will use UIX technology. The first thing to do is to create a page and specify it in struts-config.xml. With a few clicks of the mouse, you've created a simple master-detail page. Notice how navigation buttons and pagination components have been automatically added for you. Later, you can customize your view: modify labels, add a look and feel, and so forth. By default, ADF applies the 'BLAF' (browser look and feel). You can change the look and feel by editing the uix-config.xml file. However, I won't go so far as to address these issues. Just make a few simple cosmetic changes, and then run the app. You can run this application with the embedded OC4J server provided with JDeveloper by right-clicking '/main' in the Struts Data Flow Editor, and selecting Run. Not the prettiest of pages, and there are a few superfluous items, but these are minor issues that can be addressed later. The current page displays current reservations in a tabular format. Next, you will create a page to make new reservations. UIX date controls were added for your ReservationStart and ReservationEnd fields. Now, add some Struts logic. You have created some Struts mappings between the two pages of your application. You did not enter any custom code to your Struts Action at this time. If you return to the editor for main.uix, you will see a new button that the framework generated as a result of the mappings you created.
Based upon your work thus far, rerunning the application should produce a page like the one below. Try clicking the 'Add New Reservation...' button. You should be taken to your page where you can input a new reservation. Initial page of our application On the main page, notice a column entitled 'Select'. ADF provides a nice way to select a record and pass that record's unique identifier along with the request. You would typically use this to give context to an edit or delete request for a particular entry. This demonstration will only cover creating new reservations, so you can delete this field if you wish. Your application is used to reserve conference rooms. Typically, reservations might last an hour or two, but not the entire day. Viewing the data, however, it becomes apparent that you have a big problem: By default, the format mask for start and end times do not display time. In addition, now that users are able to make reservations, you need to address the issue of validation. You must ensure that users 1.) Only make reservations for a future date and 2.) Enter an end time greater than the start time. As was mentioned earlier, the ADF framework allows you to specify this type of information in your Entity objects. To do this, you need to modify the model of your application, and this makes perfect sense in this case. It is likely that you will always want the time displayed and you most definitely will want to enforce those validations. Now, return to the model and address the formatting and validation issues just described. Add identical formatting for ReservationEnd. Next, add the validation logic. You have ensured that reservations can only be made for future dates. Follow these steps to ensure that any end time specified is greater than the start time: When you created a link to your Struts Action, it created a button on the master-detail page to lead you there. It is usually a good idea to channel all requests to your Struts controller. However, if you just wanted to create a simple navigation button, you can do this easily. You need some sort of navigation from your input form, back to the main page, so you will add such a button. After applying these changes, run the application, and attempt to create some reservations. Select dates and times that violate your validation rules. An attempt to set the end time field to a time prior to the start time should result in an error message like the one below. Validation Error when Making a Reservation So, what have you accomplished? You have created a MVC-based J2EE application, in very little time, without a single line of Java code. By using a MySQL database, the ADF framework allowed you to create a fully-functional reservations system that was deployed to Oracle's OC4J server. As a final note, ADF-developed applications are not confined to Oracle's application server. JDeveloper provides support for installing the ADF libraries and packaging and deploying a complete ADF application to another J2EE application server such as JBoss. Oracle ADF provides a RAD environment for developing J2EE applications in a fast, efficient manner. Michael Klaene is a Senior Consultant with Sogeti LLC. He has spent over 9 years in Information Technology and is an experienced Systems Analyst, delivering solutions that involve numerous technologies, such as J2EE and .NET.
Rapid J2EE Development with Oracle ADF
March 24, 2005
Overview of ADF
Model
Entities
Views
Application Module
View and Controller
Controller
View
Building a Sample Application
DROP TABLE IF EXISTS conference_rooms;
CREATE TABLE conference_rooms
(
room_id INTEGER NOT NULL AUTO_INCREMENT,
room_name VARCHAR(32),
number_of_seats INTEGER,
PRIMARY KEY (room_id)
);
DROP TABLE IF EXISTS room_reservations;
CREATE TABLE room_reservations
(
reservation_id INTEGER NOT NULL AUTO_INCREMENT,
room_id INTEGER NOT NULL,
reservation_start DATETIME,
reservation_end DATETIME,
reservation_team VARCHAR(50),
PRIMARY KEY (reservation_id)
);
Building a Model

View/Controller
Making New Reservations


Conclusion
About the Author