![]() ![]() ![]() |
There are several ways to test expressions in ColdFusion application pages. If you're using ColdFusion Studio to develop your application, you can use the interactive debugger to do the following:
Or, you can also test expressions by assigning the expression to a variable and outputting its contents using the CFOUTPUT tag.
The interactive debugger in ColdFusion Studio lets you set breakpoints and watches to evaluate ColdFusion expressions. You can evaluate ColdFusion expressions at breakpoints using the Watches pane of the debugger.
You can use the evaluator box at the top of the Watches pane of the Debug window to evaluate arbitrary expressions when the debugger is suspended at a breakpoint. Use the evaluator when you want to know how an expression evaluates as you step through code, line by line.
Watches allow you to evaluate the same expression or variable every time you stop execution. When you set a watch, the debugger evaluates the watched expression. A hand pops up when the expression's value changes from one line to the next as you step through code.
The Evaluator window shows the results of the evaluation at the current point in processing the page.
The Watch area shows the values of watched expressions and any error messages in resolving these parameters.
You can use the evaluator to change values of variables, create new variables, or practice using ColdFusion functions in your expressions.
One of the simplest ways to test an expression is to write a piece of code that assigns an expression to a variable using the CFSET tag and then display the contents of the variable using CFOUTPUT. You can use this technique directly in the application page in which you are experiencing the problem.
The following example illustrates how to debug an expression using CFSET and CFOUTPUT. Imagine we are using a complex expression inside the DESTINATION attribute of the CFFILE tag.
<CFFILE ACTION="Upload" FILEFIELD="FileFormField" DESTINATION="ExpandPath('text.txt') & '\text.txt'">
To debug the expression, insert a simple CFSET and CFOUTPUT statement before the CFFILE tag:
<CFSET TempVariable=ExpandPath('text.txt') & '\text.txt'> <CFOUTPUT>Destination="#TempVariable#"</CFOUTPUT>
This CFML code assigns the expression to a temporary variable (TempVariable) and displays it enclosed in quotes. The quotes are very useful when debugging string expressions in which unwanted spaces need to be detected.
The above test code results in the following page output.
"d:\webdocs\text.txt\text.txt"
The CFOUTPUT produces results that are easily interpreted. In this case, the error occurs because of the duplication of the filename at the end of the expanded path. Using the simple test script, the problem in the expression was resolved and the correct CFFILE tag was specified as:
<CFFILE ACTION="Upload" FILEFIELD="FileFormField" DESTINATION=ExpandPath("text.txt")>
For more information on debugging and troubleshooting your applications, see the Debugging and Troubleshooting chapter of the Developing Web Applications with ColdFusion book.
See the CFML Language Reference for a full catalog of ColdFusion tags and functions.
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.