Taking input values from a request – Apple WebObjects 3.5 User Manual
Page 51
Request-Handling Methods
51
As you implement request-handling methods, you must invoke the
superclass’s implementation of the same methods. But consider where you
invoke it because it can affect the request, response, and context
information available at any given point. In short, you want to perform
certain tasks before
super
is invoked and other tasks after
super
is invoked.
Taking Input Values From a Request
The
takeValuesFromRequest:inContext:
method is invoked during the first phase of
the request-response loop, immediately after all of the objects involved in
the request have performed their
awake
methods. When this phase
concludes, the request component has been initialized with the bindings
made in WebObjects Builder.
Override
takeValuesFromRequest:inContext:
when you want to do one of the
following:
•
Access information from the request or context object.
•
Perform postprocessing on user input.
In the first case, you can place your code before the message to
super
. In the
second case, you must place your code after the message to
super
. For
example, the following implementation of
takeValuesFromRequest:inContext:
records the kinds of browsers—user agents—from which requests are
made:
// WebScript example
- takeValuesFromRequest:request inContext:context {
id userAgent = [request headerForKey:@"user-agent"];
[self recordUserAgent:userAgent];
[super takeValuesFromRequest:request inContext:context];
}
The following example performs postprocessing. It takes the values for the
street
,
city
,
state
, and
zipCode
variables and stores them in the
address
variable
formatted as a standard mailing address.
// WebScript example
- takeValuesFromRequest:request inContext:context {
[super takeValuesFromRequest:request inContext:context];
address = [NSString stringWithFormat:@"%@\n%@, %@ %@",
street, city, state, zipCode];
}
// Java example
public void takeValuesFromRequest(Request request, Context context) {
super.takeValuesFromRequest(request, context);
address = street + city + state + zipCode;
}