beautypg.com

Creating a guest list, Creating a guest list 48 – Apple WebObjects 3.5 User Manual

Page 48

background image

Chapter 2

Enhancing Your Application

48

Before doing this, it is important to understand the scope and life span of
variables in WebObjects:

Component variables, such as

currentGuest

, exist for the lifetime of the

component. These variables are defined in the component (in this case,

Main.java

) and are accessible only by its methods. Each user that uses a

component gets a separate instance of the variable.

Session variables exist for the lifetime of one user’s session and are accessible
by all code in the session. They are defined in

Session.java

. An instance of each

session variable is created for each user.

Application variables live as long as the application does and are accessible by
all code in the application. They are defined in

Application.java

. A single

instance of an application variable is shared by all users of the application.

Creating a Guest List

To store the information from all guests that have accessed the application,
you’ll create an application variable called

allGuests

, which exists for the life of the

application.

1. In Project Builder, select Classes in the first column of the Browser. Then

select

Application.java

from the second column.

The application’s code appears in the window. The following figure shows
the code generated by the Wizard, along with code you will add.