Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > WebObjects Developer's Guide


Table of Contents Previous Section

Taking Input Values From a Request

The takeValuesFromRequest:inContext: method is invoked during the first phase of the component action 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.

You might override takeValuesFromRequest:inContext: if you want to perform post-processing on user input. The following example takes the values for the component's street, city, state, and zipCode instance variables and stores them in 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(WORequest request,
WOContext context) {
super.takeValuesFromRequest(request, context);
address = street + city + state + zipCode;
}
This first phase of the component action request-response loop is only performed if the request has form values to use as input. The first request that an application receives, for example, would not have input values, and thus takeValuesFromRequest:inContext: is not performed for that first request. If you override takeValuesFromRequest:inContext:, make sure that your method is only necessary when there are form values; do not override this method to perform something that should occur for every request.

For example, it may be tempting to override takeValuesFromRequest:inContext: when you want access to information contained in the request or context objects. Because you can not guarantee that takeValuesFromRequest:inContext: will be invoked, you should not do this. Instead, you can access the request and context in the awake method this way:

- awake {
id userAgent = [[[self context] request]
headerForKey:@"user-agent"];
[self recordUserAgent:userAgent];
}

Table of Contents Next Section