Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-03

FPWebModule: BeforeResponse event?

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

leledumbo

I want to do something like this: A base module (call it ModLayout) writes a header, then a descendant module (say Mod1, Mod2 and so on) writes the inner content, ended by ModLayout writes the footer. With this scenario, the header and footer don't need to be written for each Mod1, Mod2 and so on, just once in ModLayout. However, there seems to be no BeforeResponse event that could do the header writing. There's only AfterRequest and in that event, there's no TResponse object passed.

I could put the header writing in ModLayout's OnRequest and explicitly call inherited in each Mod1, Mod2 and so on's OnRequest, but it looks dirty and error prone (one could forget to do that easily).

If without this event, does anyone have another idea?

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPWebModule-BeforeResponse-event-tp5591664p5591664.html Sent from the Free Pascal - General mailing list .

Reply by email

Unknown author
to leledumbo
leledumbo wrote 11 lines
I want to do something like this: A base module (call it ModLayout) writes a header, then a descendant module (say Mod1, Mod2 and so on) writes the inner content, ended by ModLayout writes the footer. With this scenario, the header and footer don't need to be written for each Mod1, Mod2 and so on, just once in ModLayout. However, there seems to be no BeforeResponse event that could do the header writing. There's only AfterRequest and in that event, there's no TResponse object passed. I could put the header writing in ModLayout's OnRequest and explicitly call inherited in each Mod1, Mod2 and so on's OnRequest, but it looks dirty and error prone (one could forget to do that easily).

I would do this differently.

Implement the OnRequest in ModLayout, where a virtual 'GetContent' is defined that tries the webactions. The descendants either implement webactions, or override getcontent.

Michael.

Reply by email

leledumbo
to Unknown author
Implement the OnRequest in ModLayout, where a virtual 'GetContent' is

defined that tries the webactions. The descendants either implement webactions, or override getcontent.

This could be possible. I just need to link descendant modules' OnRequest to ModLayout's one. ModLayout would be able to call GetContent whenever it wants. Nice idea. Thanks, Michael.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPWebModule-BeforeResponse-event-tp5591664p5596819.html Sent from the Free Pascal - General mailing list .

Reply by email

leledumbo
to leledumbo

Seems like I decided too quickly, how can I implement GetContent for each action? I guess it's related to your statement: "where a virtual 'GetContent' is defined that tries the webactions. The descendants either implement webactions, or override getcontent"
What do you mean by "tries the webactions"?

For now, I implement what I want by using OnAfterResponse event implemented in ModLayout. The descendant modules' actions' OnAfterResponse just link to it. Inside it, I copy AResponse.Content filled by the actions to a temporary variable (say InnerContent) and overwrite it with the layout code. InnerContent is then put back into the right place.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/FPWebModule-BeforeResponse-event-tp5591664p5598169.html Sent from the Free Pascal - General mailing list .

Reply by email