beautypg.com

Recording extra information – Apple WebObjects 3.5 User Manual

Page 153

background image

Recording Application Statistics

153

// WebScript
NSDictionary *myDict = [[[self application] statisticsStore]

statistics];

// Java
ImmutableHashTable myDict =

this.application().statisticsStore().statistics;

For a list of keys to this dictionary, see the WOStatisticsStore class
specification in the WebObjects Class Reference.

Recording Extra Information

There may be occasions when you want to have the WOStatisticsStore
object record more information than it usually does. For example, it may be
useful to know the value of a certain component variable each time the page
is accessed.

To record extra information about a page, override

descriptionForResponse:inContext:

in your component.

For example, the HelloWorld example’s Hello component could return the
value of its

visitorName

instance variable along with the component name:

// WebScript HelloWorld Hello.m
- (NSString *)descriptionForResponse:(WOResponse *)response
inContext:(WOContext *)context {

return [NSString stringWithFormat:@"%@/%@",

[self name], visitorName];

}

//Java HelloWorld Hello.java
public String descriptionForResponse(Response response, Context
context) {

return new String(this.name() + visitorName);

}

The response component receives the

descriptionForResponse:inContext:

message

after it receives the message

appendToResponse:inContext:

. The default

implementation of

descriptionForResponse:inContext:

prints the page name. Unlike

other methods invoked during the request-response loop,

descriptionForResponse:inContext:

is not sent to all components and dynamic

elements on the page; it is sent only to the top-level response component.

Note that this method receives the response and context objects as
arguments, just as

appendToResponse:inContext:

does. This means you can add

such information as the HTTP header keys, or any other information
recorded in these objects, to your description string.