Table of Contents Previous Section
Handling Direct Action Requests
As you saw in the previous section, component action requests are handled in three basic phases: taking input values from the request, invoking the action, and generating the response. The WOApplication, WOSession, and WOComponent objects are involved in each phase. Direct actions have a simpler request-response loop cycle.When the direct action request handler receives the handleRequest: message from the application, its first step is to determine what action should be performed and by what object. It does so by looking at the request URL. The URL for a direct action request looks like the one shown in Figure 27.
Figure 27. Direct Action Request URL
Since URLs can contain class names, the WODirectActionRequestHandler always checks to make sure that the class specified is a subclass of WODirectAction.
Invoking the Action
Once the direct action request handler has determined the action to be performed and which object should perform the action, the handler does the following:
- It creates an instance of the appropriate WODirectAction subclass, which in turn creates a WOContext object.
- It sends that instance a performActionNamed: message.
- In its implementation of performActionNamed:, the WODirectAction object looks for a method named actionAction. For example, if the action specified in the URL is "display", WODirectAction looks for a method named displayAction. It then invokes that method.
- If necessary, the action method takes input values from the request and assigns them either to its own local variables or to the object's instance variables.
- When it is finished processing, the action method invoked in the previous step returns either a WOResponse or WOComponent object. The WODirectAction object returns that object to the direct action request handler.
With direct actions, all input values are in the WORequest object as form values. If the form method was a "GET" then the URL contains the form values.
Generating the Response
Upon receiving a return value from performActionNamed:, the direct action request handler sends the returned object a generateResponse message. Typically, the returned object is a WOComponent. When a WOComponent receives generateResponse message, the following sequence of events take place:
- The component gets the template for itself and sends appendToResponse:inContext: to the template's root object.
- All static and dynamic HTML elements in the component's template, and in subcomponent templates, receive the appendToResponse:inContext: message. In it, they append to the content of the response the HTML code that represents them. For dynamic elements, this code includes the values assigned to variables.
Request Post-Processing
After the response has been generated, but before returning the response to the application, the direct action request handler concludes request handling by releasing the WODirectAction instance it created, or in Java, marking it for garbage collection. If the WODirectAction created a component and returned that as the response, that component is released along with the WODirectAction. Thus, in the default implementation, WODirectActions do not maintain any session state between cycles of the request-response loop.
Table of Contents Next Section