RAD Studio |  |

Responding to Request Messages with Action Items
Sending the response | Using multiple action items | See Also
Collapse All

The real work of the Web server application is performed by action items when they execute. When the Web dispatcher fires an action item, that action item can respond to the current request message in two ways:

- If the action item has an associated producer component as the value of its Producer property, that producer automatically assigns the Content of the response message using its Content method. The Internet page of the Tool palette includes a number of content producer components that can help construct an HTML page for the content of the response message.
- After the producer has assigned any response content (if there is an associated producer), the action item receives an OnAction event. The OnAction event handler is passed the TWebRequest object that represents the HTTP request message and a TWebResponse object to fill with any response information.

If the action item's content can be generated by a single content producer, it is simplest to assign the content producer as the action item's Producer property. However, you can always access any content producer from the OnAction event handler as well. The OnAction event handler allows more flexibility, so that you can use multiple content producers, assign response message properties, and so on.

Both the content-producer component and the OnAction event handler can use any objects or runtime library methods to respond to request messages. They can access databases, perform calculations, construct or select HTML documents, and so on. For more information about generating response content using content-producer components, see Generating the content of response messages.

Sending the response

An OnAction event handler can send the response back to the Web client by using the methods of the TWebResponse object. However, if no action item sends the response to the client, it will still get sent by the Web server application as long as the last action item to look at the request indicates that the request was handled.

Using multiple action items

You can respond to a request from a single action item, or divide the work up among several action items. If the action item does not completely finish setting up the response message, it must signal this state in the OnAction event handler by setting the Handled parameter to False.

If many action items divide up the work of responding to request messages, each setting Handled to False so that others can continue, make sure the default action item leaves the Handled parameter set to True. Otherwise, no response will be sent to the Web client.

When dividing the work among several action items, either the OnAction event handler of the default action item or the AfterDispatch event handler of the dispatcher should check whether all the work was done and set an appropriate error code if it is not.

See Also

Adding Actions to the Dispatcher

The Web Dispatcher

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!