CFCASE Tag - ColdFusion
>> Return to ColdFusion Tag Index
The CFCASE tag is used inside an opening and closing CFSWITCH tag. This combo of tags is used
to handle multiple condition checks of one value. It is faster and more efficient in
these cases than using multiple CFIF tags.
Syntax:
<CFCASE VALUE="value to check"
[DELIMITER="delimiter character for multiple values"]>
See also: CFSWITCH CFDEFAULTCASE
CFCASE Comments from Adobe LiveDocsLiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa9.htm I need to update my comment above: a constant expression like #'a'# or even #1+1# does indeed work as a CFCASE VALUE in CFMX (though not CF5). When testing it (before making my last comment), I had a different problem that I misinterpreted. Still, I'll hope that my identification here of what a constant expression is may help others. That said, I have to say I still don't see why one would ever use one. If any readers ever think of a practical use, I'm sure others would appreciate hearing of it.LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa9.htm Folks, the docs here suggest that a CFCASE value can be a constant or a "constant expression". Yet nowhere do I find that term defined in the CFMX 6.1 docs. Some have interpreted it to mean an expression that resolves to a constant (such as #'a'#), but any attempt to refer to pound signs in a CFCASE value gets an error in CFMX 6.1. What is meant above by constant expression? (I've noticed the CFMX 7 docs have the same issue, and will post this there for those who don't read it here.)LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa9.htm It appears that <CFCASE> cannot use a component or function scoped variables in it's value expression. The following code sets throw the same compilation error: This expression must have a constant value. <cfcomponent name="cfcase_test"> <cfset this.var1 = "1"> <cffunction name="test_this"> <cfswitch expression="1"> <cfcase value="#this.var1#">Match!/cfcase> </cfswitch> </cffunction> </cfcomponent> <cfcomponent name="cfcase_test"> <cffunction name="test_this"> <cfset var1 = 1 > <cfswitch expression="1"> <cfcase value="#var1#">Match!</cfcase> </cfswitch> </cffunction> </cfcomponent> However, using an if statement, no error is thrown and the function behaves as expected. <cfcomponent name="cfcase_test"> <cfset this.var1 = "1"> <cffunction name="test_this"> <cfif this.var1 eq "1">Match!</cfif> </cffunction> </cfcomponent> I assume this has to do with the way Neo's Assembler/Translation engine compiles the switch statement, requiring the value to be known a the time of compilation rather than runtime as with an if statement?? --MikeLiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa9.htm I'm trying to test both for "equals" and "greater than" in a cfswitch statement. It seems to me I should be able to do: <cfswitch expression = #redirect.RecordCount#> <cfcase value = "0"> <!--- Do nothing but show variables.message in the body below ---> </cfcase> <cfcase value="1"> <cflocation URL="#redirect.newurl#" addtoken="no"> </cfcase> <cfcase value GT 1> <cfset variables.multiplelinks=true> <cfset variables.message="The page you are looking for may have moved to one of the following addresses:"> </cfcase> <cfdefaultcase> How come I get the error message "Invalid token '1' found on line 40 at column 50."?LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa9.htm I'm trying to use cfcase with a variable expression, which the documentation says should work, but it doesnt appear to (indeed, it breaks the error mechanism). I have: <cfset pendingUser="foo"> <cfswitch expression="#getUser.status#"> <cfcase value="#pendingUser#" delimiters=","> <cfset foo="bar"> </cfcase> </cfswitch> and cold fusion generates an error saying that the expression must be constant, but that it cant determine where the error is. If I change the <cfcase> to <cfcase value="foo">, it works fine.LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa9.htm This is a known issue in ColdFusion MX 6.1 (bug number 53339).LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-pa9.htm <cfbreak> now also works in conjunction with a <cfswitch>. This is really screwy and isn't backwards compatible with cf5. Run this on a cf5 and a cfmx machine and you'll see what I mean: <cfloop from="1" to="5" index="count"> <cfoutput>#count#<br></cfoutput> <cfswitch expression="#count#"> <cfcase value="3"><cfbreak></cfcase> </cfswitch> <cfif count is 4><cfbreak></cfif> </cfloop> on cf5 it displays: 1 2 3 on cfmx it displays 1 2 3 4[Top]
Recommended Books
COLDFUSION MX Web Application Construction Kit (5th Edition)
Authors: Ben Forta and Nate Weiss
1500 pages
[Top]
Web Sites
[Top]