PATH  WebObjects 4.0 Documentation > What's New in WebObjects 4.0

Table of Contents Previous Section

How Direct Action Requests Are Received

Clicking the WOHyperlink from the previous section generates a URL that looks something like this:

http://localhost/cgi-bin/WebObjects/AppName.woa/wa/
display?sku=value&aKey=aValue...
The wa after the application name is a request handler key. It specifies which WORequestHandler should handle the request. WORequestHandler is a new class in WebObjects 4.0. You can read more about it under WORequestHandler Class. The wa string is the key for the WODirectActionRequestHandler, a private subclass of WORequestHandler.

In WebObjects 4.0, when the WOApplication receives a request from the WOAdaptor, it looks at the request handler key to determine which WORequestHandler should handle the request. It then sends that WORequestHandler a handleRequest: message.

If the URL doesn't have a request handler key (as is the case with the initial URL used to begin a session with a WebObjects application), WOApplication uses whatever its default request handler is set to be. By default, the default request handler is WOComponentRequestHandler, which performs the request handling scheme that you're used to. If you want to write an application entirely using direct actions, set the default request handler in your WOApplication's init method or constructor in this way:

// Java implementation
public WOApplication() {
super();
...
setDefaultRequestHandler(requestHandlerForKey(
WOApplication.directActionRequestHandlerKey()));
...
}
//WebScript implementation
- init {
self = [super init];
...
[self setDefaultRequestHandler:[self requestHandlerForKey:
[WOApplication directActionRequestHandlerKey]]];
...
return self;
}
If WODirectActionRequestHandler is the default request handler, the first request triggers the defaultAction method, which is declared for you in your DirectAction class.

In its implementation of handleRequest:, WODirectActionRequestHandler extracts the direct action class and the action from the URL. (If your WODirectAction subclass isn't named DirectAction, the class name appears in the URL immediately before the action.) WODirectActionRequestHandler then sends the message performActionNamed: to your WODirectAction object.

Each action method in your WODirectAction class should end with the string "Action" and should return either a WOComponent or a WOResponse object. For example:

- (WOComponent *)displayAction
There's a new protocol and interface named WOActionResults conformed to by WOResponse and WOComponent. Your action may actually return any object that conforms to WOActionResults.

When the action method returns, WODirectActionRequestHandler sends the message generateResponse to the object returned by the action method. This is the method defined in the WOActionResults protocol. generateResponse returns a WOResponse object. WOResponse's implementation is simply to return itself. WOComponent's implementation translates the component into a WOResponse by sending itself appendToResponse:inContext:.

Note: WOComponent's generateResponse method is also useful for the handleException... methods defined in WOApplication.

Upon receiving the WOResponse, WODirectActionRequestHandler returns the response to the WOApplication, and the WOApplication passes it to the WOAdaptor.

Table of Contents Next Section