The QuickBookingModel JavaBean

The JavaBean class QuickBookingModel should be able to store all the data that are needed for the client to display a booking. QuickBookingModel will be initialized in the session bean and passes the booking data either to the client or to the Web service.

For this purpose, the QuickBookingModel must contain a field for each relevant value. The fields will be named bookingId,  vehicleTypeId, dateFrom, dateTo, pickupLocation, and dropoffLocation, similar to their definition in the entity bean. However, unlike the definition in the entity bean, the fields dateFrom and dateTo are defined as Strings in this class. This ensures that the data in the client can be displayed at once. In addition, the field price is defined here. This field contains the total price of the booking and is calculated by the business logic in the session bean. In contrast, the values from the fields reservationDate and status from the entity bean are not needed here and are not included in the JavaBean class.

Moreover, QuickBookingModel must be serializable, so that it can be passed to a Web service. That is, the bean class must implement the Serializable interface.

Prerequisites

The structure of the Java project Helperclasses is currently displayed in the Package Explorer.

Procedure

Creating the JavaBean QuickBookingModel in the Java project.

...

       1.      In the Package Explorer, select the project node Helperclasses.

       2.      From the context menu, choose  New ® Other...

       3.      Select Java (in the left pane), followed by Class (in the right pane). Choose Next.

       4.      In the New Java Class wizard that appears, assign the following values:

   

Source Folder

Helperclasses

Package

com.sap.engine.examples.util

Name

QuickBookingModel

Modifiers

public

Superclass

java.lang.Object

Interfaces

java.io.Serializable

Inherited abstract methods

activated

To add the java.io.Serializable interface, choose Add and enter Serializable in the dialog box. Then choose java.io as the Qualifier.

       5.      Leave all the other suggested values unchanged and choose Finish.

The wizard creates the new JavaBean class QuickBookingModel in the Java Editor.

Implementing the JavaBean QuickBookingModel

At this point, you will define the necessary fields and generate the associated get/set methods.

       6.      In the Java Editor, add the following field definitions to the body of the class:

 

  private java.lang.String bookingId;

  private java.lang.String vehicleType;

  private java.lang.String dateFrom;

  private java.lang.String dateTo;

  private java.lang.String pickupLocation;

  private java.lang.String dropoffLocation;

  private java.lang.String price;

 

       7.      In the Java Editor, select all the lines with the field definitions you have just added and click the right mouse button.

       8.      ChooseSource ® Generate Getter and Setter from the context menu.

       9.      In the selection dialog that appears, choose Select All and confirm your choice by choosing OK.

The appropriate get and set methods are generated automatically for all the fields.

   10.      If you need to correct the formatting, choose the Format function from the context menu of the Java Editor.

   11.      Save the contents of the editor by choosing the appropriate icon in the toolbar.

Result

You have created and completely implemented the JavaBean class QuickBookingModel.

Next step:

The Exception Class QuickCarRentalException