October 22, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Rapid J2EE Development with Oracle ADF

  • March 24, 2005
  • By Michael Klaene
  • Send Email »
  • More Articles »

Making New Reservations

The current page displays current reservations in a tabular format. Next, you will create a page to make new reservations.

  • From the Component Palette, drag a second Data Page onto the Struts Data Flow Editor.
  • Name this component '/newReservations'.
  • Double-click and select the value '/newReservations.uix'. Click OK.
  • In the Data Control Palette, select the RoomReservationsView2 instance (the one not beneath ConferenceRoomsView1).
  • Select Input Form and drag it onto the page to create an input page.
  • Because ReservationId is auto generated, remove this binding by highlighting it in the editor and pressing delete.

UIX date controls were added for your ReservationStart and ReservationEnd fields. Now, add some Struts logic.

  • From the Struts Page Flow group in the Component Palette, select Action.
  • Drag Action onto the flow diagram to create a new Struts Action.
  • Name this Action 'NewReservationAction', and then double-click the Action to create a source file for it.
  • Close the code editor that appears containing the new Struts Action.
  • Select Page Link from the Component Palette.
  • Click '/main' in the diagram, and then the Struts Action 'NewReservationAction' to create a link.
  • Select Forward from the Component Palette.
  • Click Action 'NewReservationAction' in the diagram, then '/newReservations' to create a Struts Forward from this Action to the form.
  • In the editor, highlight the Forward named 'success' and change it to 'create'.

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.

  • In the Property Inspector, change the button text to 'Add New Reservation...'

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.

  • In the Applications - Navigator, right-click the RoomReservations Entity and open it for editing.
  • Expand Attributes; highlight ReservationStart.
  • Select the Control Hints tab.
  • Select a Format Type of 'Simple Date'.
  • Select a Format of 'MM/dd/yyyy HH:mm'.

Add identical formatting for ReservationEnd. Next, add the validation logic.

  • With RoomReservations still open, select Validation.
  • Highlight ReservationStart and click New....
  • You are creating a 'CompareValidator', so leave the Rules as is.
  • Select 'GreaterThan' for Operator.
  • Select 'Query Result' for Compare With.
  • Select the current system date using MySQL syntax by entering 'SELECT NOW();' in the Enter SQL statement field.
  • Error Message should contain the text: 'Start time must be greater than the current time!'

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:

  • Select Validation.
  • Highlight ReservationEnd and click New....
  • Leave Rules and Operator as is ('CompareValidator' and 'GreaterThan').
  • Instead of 'Query Operator', select 'View Object Attribute' for Compare With.
  • Under Select Attribute, select ReservationStart from RoomReservationsView.
  • Error Message should contain the text: 'End time must be 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.

  • Click the Components tab to show the Component Palette. Go to the 'All UIX Components' section.
  • Select Button and drag it onto the editor for the 'newReservations.uix' page.
  • Set the button label to 'View All Reservations' in the Property Inspector.
  • In the destination property, select main.do from the drop-down to create a link back to the first page.

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

Conclusion

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.

About the Author

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.





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel