Adobe COLDFUSION 9 Manual page 252

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Using the onRequest method
The
method differs from the
onRequest
intercepts the user's request. This difference has two implications:
• ColdFusion does not process the request unless you explicitly call it, for example, by using a
behavior lets you use the
determines the pages or page contents to be displayed.
• When you use
cfinclude
As a result, any method in the CFC that executes can set the page's Variables scope variables, and the
method can access any Variable scope values that the included page has set or changed. Therefore,
onRequestEnd
for example, the
onRequestStart
To use this method as a filter, place the
<cffunction name="onRequest">
<cfargument name = "targetPage" type="String" required=true/>
<cfsavecontent variable="content">
<cfinclude template=#Arguments.targetPage#>
</cfsavecontent>
<cfoutput>
#replace(content, "report", "MyCompany Quarterly Report", "all")#
</cfoutput>
</cffunction>
For more information, see the entry for onRequest in the CFML Reference
Using the onRequestEnd method
You use the
onRequestEnd
through ColdFusion MX 6.1, you would use the OnRequestEnd.cfm page for such code). Typical uses include
displaying dynamic footer pages. For an example, see onSessionEnd in the CFML Reference.
Note: If you do not include an
Variables scope with the requested page, but it does share Request scope variables.
For more information, see the entry for onRequestEnd in the CFML Reference.
Handling errors in Application.cfc
The following sections briefly describe how you to handle errors in Application.cfc. For more information on error
pages and error handling, see
onError in the CFML Reference.
Application.cfc error handling techniques
Application.cfc handles errors in any combination of the following ways:
• Use try/catch error handling in the event methods, such as
exceptions that happen in the event methods.
• Implement the onError method. This method receives all exceptions that are not directly handled by try/catch
handlers in CFML code. The method can use the
for handling.
• Use
tags in the application initialization code following the
cferror
that sets the application's This scope variables. These tags specify error processing if you do not implement an
method, or if the
onError
validation error handler, for example, by placing the following tag in the CFC initialization code:
onRequestStart
method to filter requested page content or to implement a switch that
onRequest
to process request, the CFC instance shares the Variables scope with the requested page.
or
method set variables that are used on the page.
onRequest
tag inside a
cfinclude
method for code that should run at the end of each request. (In ColdFusion versions
method in Application.cfm file, the
onRequest
"Handling
Errors" on page 275 For details on implementing the onError method, see
cfthrow
method throws an error. You could implement an application-specific
onError
Last updated 8/5/2010
method in one major way: the
tag, as the following example shows:
cfsavecontent
onRequestEnd
or
onApplicationStart
tag to pass any errors it does not handle to ColdFusion
tag, typically following the code
cfcomponent
method
onRequest
tag. This
cfinclude
method does not share a
, to handle
onRequestStart
247

Advertisement

Table of Contents
loading

Table of Contents