Chaining Page Producers Together

From RAD Studio
Jump to: navigation, search

Go Up to Using Page Producer Components


The replacement text from an HTTPProd.OnHTMLTag event handler need not be the final HTML sequence you want to use in the HTTP response message. You may want to use several page producers, where the output from one page producer is the input for the next.

The simplest way is to chain the page producers together is to associate each page producer with a separate action item, where all action items have the same PathInfo and MethodType. The first action item sets the content of the Web response message from its content producer, but its OnAction event handler makes sure the message is not considered handled. The next action item uses the ContentFromString method of its associated producer to manipulate the content of the Web response message, and so on. Action items after the first one use an OnAction event handler such as the following:

 procedure WebModule1.Action2Action(Sender: TObject; Request: TWebRequest;
    Response: TWebResponse; var Handled: Boolean);
 begin
   Response.Content := PageProducer2.ContentFromString(Response.Content);
 end;
 void __fastcall WebModule1::Action2Action(TObject *Sender,
    TWebRequest *Request, TWebResponse *Response, bool &Handled)
 {
   Response->Content = PageProducer2->ContentFromString(Response->Content);
 }

For example, consider an application that returns calendar pages in response to request messages that specify the month and year of the desired page. Each calendar page contains a picture, followed by the name and year of the month between small images of the previous month and next months, followed by the actual calendar. The resulting image looks something like this:

Calex.jpg

The general form of the calendar is stored in a template file. It looks like this:

<HTML>
<Head></HEAD>
<BODY>
<#MonthlyImage> <#TitleLine><#MainBody>
</BODY>
</HTML>

The OnHTMLTag event handler of the first page producer looks up the month and year from the request message. Using that information and the template file, it does the following:

  • Replaces <#MonthlyImage> with <#Image Month=January Year=2000>.
  • Replaces <#TitleLine> with <#Calendar Month=December Year=1999 Size=Small> January 2000 <#Calendar Month=February Year=2000 Size=Small>.
  • Replaces <#MainBody> with <#Calendar Month=January Year=2000 Size=Large>.

The OnHTMLTag event handler of the next page producer uses the content produced by the first page producer, and replaces the <#Image Month=January Year=2000> tag with the appropriate HTML <IMG> tag. Yet another page producer resolves the #Calendar tags with appropriate HTML tables.

See Also