Show TOC Start of Content Area

Procedure documentation The Constants Class  Locate the document in its SAP Library structure

 

In the Constants class, you define constants that the application needs. These constants will be used by the beans in the EJB project or by the servlet and the JSP in the Web project.

You will declare the following Constants in the constants class:

Constants

Description

STATUS_ACTIVE, STATUS_CANCELLED

These two constants indicate the status of a booking. They are used in the business logic of a session bean to inform the entity bean of the status of the current booking.

 

ACTION_SAVE,  ACTION_CANCEL

These constants specify the action that the user at the client end has just carried out. The JSP and the servlet need them, so that they know what button the user has just clicked.

 

RESERVATIONS, CLIENT_MESSAGE

These constants are used to store, in the session bean, the context data for the booking and for messages displayed for the user.

Both constants are initialized in the session bean.

 

LOCATION, VEHICLE_TYPE

 

These constants contain an array with data for the reservation location and the car type.

 

Prerequisites

This graphic is explained in the accompanying textThis graphic is explained in the accompanying text

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

 

Procedure

Creating the Java class Constants in the Java project

...

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

       2.      From the context menu, choose New Class

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

 

 

Source Folder

Helperclasses

Package

com.sap.engine.examples.util

Enclosing type

unchecked

Name

Constants

Modifiers

public

Superclass

java.lang.Object

Inherited abstract methods

checked

 

 

This graphic is explained in the accompanying text

 

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

The wizard creates the package com.sap.engine.examples.util, locates the new class Constants there and opens the Java Editor.

Defining Constants

       5.      In the Java Editor, add the following constant definitions to the body of the class:

 

public static final java.text.SimpleDateFormat FORMATTER = new      java.text.SimpleDateFormat("dd.MM.yyyy");

 

public static final java.lang.String STATUS_ACTIVE = "ACTIVE";

public static final java.lang.String STATUS_CANCELLED = "CANCELLED";

 

public static final int ACTION_SAVE = 0;

public static final int ACTION_CANCEL = 1;

 

public static final String RESERVATIONS =    "rent.car.customer.reservations";

public static final String CLIENT_MESSAGE = "rent.car.customer.message";

 

public static final String[] LOCATION =   {"Heidelberg","Frankfurt","Kassel","Berlin","Mannheim","Leipzig","Hamburg" };

public static final String[] VEHICLE_TYPE =    {"Economy","Compact","Intermediate","Full Size","Premium","Luxury","Convertible","Mini Van" };

 

 

       6.      If necessary, correct the formatting of these lines by choosing Source Format from the context menu.

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

Result

You have created and completely implemented the auxiliary class Constants.

 

Next step:

The QuickBookingModel JavaBean

 

 

 

End of Content Area