Table of Contents
Previous Section
This method is invoked before the application generates HTML for the response. You can use this method to substitute a different object for the response page before a response is composed. If this method returns a non-nil value, generateResponse: inContext: is sent to the substituted object. If you implement this method in the application and return a non-nil value, the substitute object will also receive a willGenerateResponse:inContext: message.
The most common use of this method is to implement security features. You can use willGenerateResponse:inContext: to return a login page if the user has not yet provided valid login information. The advantage of using willGenerateResponse: inContext: over any other hook is that this method is always invoked before generating a response.
You can't rely upon an action to implement the same functionality. By specifying a page in a URL, a user can attempt to access any page in an application without invoking an action. For example, you can access the second page of HelloWorld without invoking the sayHello action by opening the URL:
http://serverhost/cgi-bin/WebObjects/Examples/HelloWorld/Hello.wo/
When a WebObjects application receives such a request, it cycles through the request-response loop as usual, but there is no user input to store and no action to invoke. As a result, the object representing the requested page---Hello in this case---generates the response.
By implementing a login mechanism in willGenerateResponse:inContext:, you can prevent users from accessing pages without authorization.