View comments | RSS feed

onRequest

Description

Runs when a request starts, after the onRequestStart event handler. If you implement this method, it must explicitly call the requested page to process it.

Syntax

<cffunction name="onRequest" returnType="void">
   <cfargument name="targetPage" type="String" required=true/>
   ...
   <cfinclude template="#Arguments.targetPage#">
   ...
</cffunction>

See also

onRequestStart, onRequestEnd, Method summary, Managing requests in Application.cfc in ColdFusion MX Developer's Guide

Parameters

ColdFusion MX passes the following parameters to the method:

Parameter Description

targetPage

Path from the web root to the requested page.

Returns

This method does not return a value; do not use the cfreturn tag.

Usage

This event handler provides an optional request filter mechanism for CFML page requests (that is, .cfm pages requested using a browser). Use it to intercept requests to target pages and override the default behavior of running the requested pages. The following rules specify where and how you use the onRequest method.

You can use this method to do preprocessing that is required for all requests. Typical uses include filtering and modifying request page contents (such as removing extraneous white space), or creating a switching mechanism that determines the exact page to display based on available parameters.

Example

<cffunction name="onRequest">
   <cfargument name="targetPage" type="String" required=true/>
   <cfset var content="">
   <cfsavecontent variable="content">
      <cfinclude template="#Arguments.targetPage#">
   </cfsavecontent>
   <cfoutput>
      #replace(content, "report", "MyCompany Quarterly Report", "all")#
   </cfoutput>
</cffunction>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


elpestybandito said on Jun 21, 2006 at 7:10 AM :
You can use web services, flash remoting or event gateway requests CFC's with an Application.cfc containing an onRequest method. This can be done by creating another application.cfc within a subfolder where your CFC's are, containing the code...

<cfcomponent name="Application" extends="test.Application">
<cfset StructDelete(variables,"onRequest")/>
<cfset StructDelete(this,"onRequest")/>
</cfcomponent>

*Thanks to Sean Corfield
nummsa said on Dec 31, 2007 at 2:25 PM :
elpestybandito -

Great quick cut-n-paste solution for this. Thanks for Sean Corfield, Ray Camden, etc. for really pointing out a solution to this - but elpestybandito's was the easiest for us to implement. I have a /root/Application.cfc file with an onRequest and onRequestEnd declaration. elpestybandito's will work only if you have just an onRequest and not an onRequestEnd in the /root/Application.cfc. If the CFC you are exposing through flash remoting are in /root/subdir/ and are behind a /root/Application.cfc with onRequest, onRequestEnd and onError functions, the following /root/subdir/Application.cfc will work:

<cfcomponent extends="/.Application">
<cfset StructDelete(variables,"onRequest")/>
<cfset StructDelete(this,"onRequest")/>
<cfset StructDelete(variables,"onRequestEnd")/>
<cfset StructDelete(this,"onRequestEnd")/>
</cfcomponent>

It might be wise to clear all the Application.cfc functions from this /root/subdir/'s application scope, not just onRequest and onRequestEnd.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000698.htm