Binding the class’s instance variables to the form – Apple WebObjects 3.5 User Manual
Page 42

Chapter 2
Enhancing Your Application
42
also a class, specifically a subclass of the class next.wo.Component (called
WOComponent in WebScript or Objective-C).
Java classes require a constructor to initialize an instance (or object) of a
particular class whenever one is created. A constructor has the same name
as the class and returns no value.
Whenever your application creates a new Guest class, its instance variables
are initialized with empty strings, which is the default value if the user
enters no data. (If you prefer, you can use different strings for these initial
values.)
6. Save
Guest.java
.
Saving the file lets WebObjects Builder know about your newly created
Guest class.
Binding the Class’s Instance Variables to the Form Elements
In the first chapter, you bound the input elements to variables in Main’s code.
Now you’ll modify the bindings to use the class you just created.
1. Select Web Components in the first column of the browser.
2. Double-click
Main
in the second column of the browser to open the
component in WebObjects Builder.
3. Using the Add Variable/Method panel, add a variable called
currentGuest
to
your component and specify its type as Guest. (Note that you can now
choose Guest from the Type pop-up menu.)
An entry for
currentGuest
appears in the object browser. Notice the “>”
symbol to the right of its name. This means that there is additional data to
be displayed in the second column.
4. Select
currentGuest
in the object browser.
The second column displays the three fields of
currentGuest
, as determined
by the definition of its class, Guest.
5. Click
guestName
in the second column of the object browser next to
currentGuest
and drag the cursor to the Name text field.
This time, when the Inspector opens, there is already a binding for the
value
attribute (
guestName
), because you bound it in the first tutorial.