
249
DEVELOPING
COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Las
t
upda
te
d 8/5/2010
<cfcomponent>
<cfset This.name = "BugTestApplication">
<cffunction name="onError">
<!--- The onError method gets two arguments:
An exception structure, which is identical to a cfcatch variable.
The name of the Application.cfc method, if any, in which the error
happened.
<cfargument name="Except" required=true/>
<cfargument type="String" name = "EventName" required=true/>
<!--- Log all errors in an application-specific log file. --->
<cflog file="#This.Name#" type="error" text="Event Name: #Eventname#" >
<cflog file="#This.Name#" type="error" text="Message: #except.message#">
<!--- Throw validation errors to ColdFusion for handling. --->
<cfif Find("coldfusion.filter.FormValidationException",
Arguments.Except.StackTrace)>
<cfthrow object="#except#">
<cfelse>
<!--- You can replace this cfoutput tag with application-specific
error-handling code. --->
<cfoutput>
<p>Error Event: #EventName#</p>
<p>Error details:<br>
<cfdump var=#except#></p>
</cfoutput>
</cfif>
</cffunction>
</cfcomponent>
To test this example, place a CFML page with the following code in the same page as the Application.cfc file, and enter
valid and invalid text in the text input field.
<cfform>
This box does Integer validation:
<cfinput name="intinput" type="Text" validate="integer" validateat="onServer"><br>
Check this box to throw an error on the action page:
<cfinput type="Checkbox" name="throwerror"><br>
<cfinput type="submit" name="submitit">
</cfform>
<cfif IsDefined("form.fieldnames")>
<cfif IsDefined("form.throwerror")>
<cfthrow type="ThrownError" message="This error was thrown from the bugTest action
page.">
<cfelseif form.intinput NEQ "">
<h3>You entered the following valid data in the field</h3>
<cfoutput>#form.intinput#</cfoutput>
</cfif>
</cfif>
Note:
For more information on server-side validation errors, see “
Validating Data
” on page
743.
Example: a complete Application.cfc
The following example is a simplified Application.cfc file that illustrates the basic use of all application event handlers:
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...