View comments | RSS feed

cfexit

Description

This tag aborts processing of the currently executing CFML custom tag, exits the page within the currently executing CFML custom tag, or re-executes a section of code within the currently executing CFML custom tag.

Category

Debugging tags, Flow-control tags

Syntax

<cfexit 
method = "method">

See also

cfabort, cfbreak, cfexecute, cfif, cflocation, cfloop, cfswitch, cfthrow, cftry; cfabort and cfexit in Elements of CFML in ColdFusion MX Developer's Guide

Attributes

Attribute Req/Opt Default Description

method

Optional

exitTag

  • exitTag: aborts processing of currently executing tag.
  • exitTemplate: exits page of currently executing tag.
  • loop: re-executes body of currently executing tag.

Usage

If this tag is encountered outside the context of a custom tag, for example in the base page or an included page, it executes in the same way as cfabort. The cfexit tag can help simplify error checking and validation logic in custom tags.

The cfexit tag function depends on its location and execution mode:

Method value Location of cfexit call Behavior

exitTag

Base page

Terminate processing

 

Execution mode = Start

Continue after end tag

 

Execution mode = End

Continue after end tag

exitTemplate

Base page

Terminate processing

 

Execution mode = Start

Continue from first child in body

 

Execution mode = End

Continue after end tag

loop

Base page

Error

 

Execution mode = Start

Error

 

Execution mode = End

Continue from first child in body

Example

<h3>cfexit Example</h3>
<p>cfexit can be used to abort the processing of the currently executing 
CFML custom tag. Execution resumes following the invocation of
the custom tag in the page that called the tag. <h3>Usage of cfexit</h3> <p>cfexit is used primarily to perform a conditional stop of processing
inside a custom tag. cfexit returns control to the page that
called that custom tag, or in the case of a tag called by another
tag, to the calling tag. <!--- cfexit can be used within a CFML custom tag, as follows: ---> <!--- Place this code (uncomment the appropriate sections) within the
customtags directory. ---> <!--- MyCustomTag.cfm ---> <!--- This simple custom tag checks for the existence. of myValue1 and myValue2. If they are both defined, the tag adds them and returns the result to the calling page in the variable "result". If either or both of the expected attribute variables is not present, an error message is generated, and cfexit returns control to the calling page. ---> <!--- <cfif NOT IsDefined("attributes.myValue2")> <cfset caller.result = "Value2 is not defined"> <cfexit method = "exitTag"> <cfelseif NOT IsDefined("attributes.myValue1")> <cfset caller.result = "Value1 is not defined"> <cfexit method = "exitTag"> <cfelse> <cfset value1 = attributes.myValue1> <cfset value2 = attributes.myValue2> <cfset caller.result = value1 + value2> </cfif> ---> <!--- End MyCustomTag.cfm ---> <!--- Place this code within your page ---> <!--- <p>The call to the custom tag, and then the result: <CF_myCustomTag myvalue2 = 4> <cfoutput>#result#</cfoutput> ---> <p>If cfexit is used outside a custom tag, it functions like a cfabort.
For example, the text after this message is not processed: <cfexit> <p>This text is not executed because of the cfexit tag above it.

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

Version 7

Comments


No screen name said on Dec 1, 2005 at 6:24 AM :
I don't think it's correct that cfexit aborts all processing when called from a cfincluded file. My tests (cf7) show that it stops processing of the included file that contains the cfexit call, but processing of the calling page continues after the cfinclude. This is the same behavior as when called from a cfmoduled file.
SamCurren said on May 3, 2007 at 5:35 AM :
"If this tag is encountered outside the context of a custom tag, for example in the base page or an included page, it executes in the same way as cfabort."
Not quite true. cfabort will quit all processing, and not run code inside the onRequest method of Application.cfc, while cfexit within a normal cfml page will return from that template, and still run the onRequest code.
This behavior is very useful for situations where templating is applied inside onRequest.

 

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/00000244.htm