Action methods – Apple WebObjects 3.5 User Manual

Page 43

Advertising
background image

43

The methods that you write for your WebObjects application provide the
behavior that makes your application unique. Because you are writing
subclasses of WOApplication, WOSession, and WOComponent (in Java,
WebApplication, WebSession, and Component), you inherit the methods
provided by those classes. These inherited methods take care of the details
of receiving HTTP requests and generating responses. However, you’ll
sometimes find that you need to override some of the inherited methods to
perform certain tasks.

This chapter describes the types of methods that you generally write in a
WebObjects application. These types are:

Action methods

Initialization and deallocation methods

Request-handling methods

In cases where you override existing methods, those methods are invoked
at standard, predictable times during the application’s request-response
loop (the main loop for a WebObjects application). For background on the
request-response loop, see the chapter “WebObjects Viewed Through Its
Classes” (page 63).

As you’re writing methods, refer to the class specifications for
WOApplication, WOSession, and WOComponent to learn which messages
you can send to these objects. The class specifications are in the online
book WebObjects Class Reference.

Action Methods

An action method is a method you associate with a user action—for instance,
clicking a submit button, an active image, or a hyperlink. To associate your
method to a user action, you map it to a dynamic element that has an
attribute named

action

. (In the examples just given, the dynamic elements

associated with the user actions are WOSubmitButton, WOActiveImage, or
WOHyperlink.) When the user performs the associated action, your
method is invoked.

For example, in the HelloWorld example application (in

<DocRoot>/WebObjects/Examples/WebScript/HelloWorld

, where

<DocRoot>

is your web

server’s document root), the submit button is mapped to a method named

sayHello

in the Main component. When users see this page, they type in a

Advertising