Dave,

Maybe it's just me (it's still early), but I don't understand how your
example with evaluate() can be considered a workaround for a parameter that
doesn't exist.  Using the example you specified still results in the same
error.  Here was Brent's original code (the source of this whole thread):

<cfset orderString =
iif(isDefined("attributes.order"),DE("&amp;order=#attributes.order#"), "")>
<cflocation url="index.cfm?fuseaction=tools#orderString#>

If I'm understanding your workaround example correctly, here's what you're
proposing instead:

<cfset orderString =
iif(isDefined("attributes.order"),DE("#evaluate('&amp;order=#attributes.orde
r#')#"), "")>
<cflocation url="index.cfm?fuseaction=tools#orderString#">

Both of these code example produce the exact same result - "Error resolving
parameter attributes.order"

Am I missing something?  :)

Regards,
Tyson

-----Original Message-----
From: Dave Feltenberger [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 30, 2001 9:41 AM
To: CF-Talk
Subject: RE: IIF and DE



ColdFusion doesn't "validate" the entire statement block per se, it's just
that the variables you pass in are parameters to a function and have to
exist in order to pass in.  Hence the workaround I sent before of using
evaluate().

Other languages that "short circuit" in if/else if/else blocks still have to
have variables defined in order to pass into functions - there's no magic
there - it just skips the rest of the block once it matches a condition
specified.  The compiler will complain if the variables aren't defined ahead
of time in languages like C, C++, Java, etc., and since you don't have the
option of compiling ColdFusion (as far as I know, anyway) to rid yourself of
errors like this, you hit the problem at run-time.  IIF does in fact "short
circuit" like it's supposed to.


-----Original Message-----
From: Tyson Vanek [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 30, 2001 10:31 AM
To: CF-Talk
Subject: RE: IIF and DE


Not exactly.  IIF() creates an IF/ELSE scenario which, technically speaking,
could be considered two statements even though only one of them actually has
a condition defined.

Fact of the matter is, this comes down to what's called "short circuit"
logic.  In most languages in any if/else pair, once a match with one of the
if clauses is established, the rest of the if/else statement is simply
ignored - commonly referred to as "short circuiting".  You'll find that
ColdFusion works this way with CFIF, CFELSEIF and CFELSE.  However, in the
case of IIF(), ColdFusion doesn't short circuit which means that it tries to
validate the entire statement block, even though only part of it actually
needs to execute.



---[ begin example 1 ]---
<cfset strFoo = "foo">
<cfif isDefined("strFoo") and len(trim(strFoo))>
        <cfoutput>strFoo = #strFoo#</cfoutput>
<cfelse>
        <cfoutput>strFoo2 = #strFoo2#</cfoutput>
</cfif>
---[ end example 1 ]---

---[ begin example 2 ]---
<cfset strFoo = "foo">
<cfoutput>
        #iif(isDefined("strFoo") and len(trim(strFoo)),de(strFoo),de(strFoo2))#
</cfoutput>
---[ end example 2 ]---

Hope that makes sense and/or helps.  :)

-Tyson

-----Original Message-----
From: Brent Goldman [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 29, 2001 8:05 PM
To: CF-Talk
Subject: RE: IIF and DE


Hi,

Good idea, but I think you missed the problem.  There is not two different
expressions to evaluate to be TRUE or FALSE as in your example -- just the
isDefined function.  CF shouldn't be executing the "... blah blah blah ...",
but it does, and that is the problem.

-Brent

-----Original Message-----
From: Tyson Vanek [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 29, 2001 5:57 PM
To: CF-Talk
Subject: RE: IIF and DE


This goes back to the way the old <CFIF> used to behave.  In the past (I
think up until CF ver 4.5), the same problem existed with <CFIF>.  Here's an
example.  Say that the parameter "strFoo" doesn't exist, consider the
following code:

<cfif isDefined("strFoo") and len(trim(strFoo))>
        ... blah blah blah ...
<cfelse>
        ... blah2 blah2 blah2 ...
</cfif>

In the past, ColdFusion would choke on the CFIF statement when "strFoo" was
not defined, even though you'd expect it to immediately jump to the CFELSE
statement once the isDefined() returned false.  I believe this was fixed
with the release of ColdFusion 4.5 - I might be wrong on the version number.

My guess is that this behavior is still leftover in the iif() function.
I've noticed this in my own development as well that I never seem to be able
to use an isDefined() check in an iif() block.  Doing so always results in
the "Error resolving parameter" error.

A workaround would be to set a default for the variable using CFPARAM and
then changing your iif() logic.  Here's an example:

<cfparam name="attributes.order" default="">
<cfset orderString =
iif(len(trim(attributes.order)),de("&amp;order=#attributes.order#"),"")>
<cflocation url="index.cfm?fuseaction=tools#orderString#">

Hope this helps,
Tyson

-----Original Message-----
From: Brent Goldman [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 29, 2001 7:36 PM
To: CF-Talk
Subject: IIF and DE


Hi,

I'm trying to use IIF with DE, and it doesn't seem to be working.  My code:
<cfset orderString = iif(isDefined("attributes.order"),
DE("&amp;order=#attributes.order#"), "")>
<cflocation url="index.cfm?fuseaction=tools#orderString#>

What I am trying to do is this: if a certain variable is defined
(attributes.order), then create a string that can be appended to a URL,
otherwise make the string blank.
The desired results:
   - If attributes.order is set to "name", then orderString should be set to
"&amp;order=name"
   - If attributes.order is undefined, then orderString should be set to ""

The problem is that when attributes.order is undefined, ColdFusion still
tries to execute the code that should be executed if the first expression
was true, thus giving an error.  CF is trying to find the value of
attributes.order in the DE("&amp;order=#attributes.order#") statement, even
though attributes.order is undefined, and that statement should go with
being evaluated.

This problem is kinda hard to explain, but does anyone have any idea on how
to fix this??? (without having to use CFIF/CFELSE - the whole point is that
I want to use IIF and DE)

Thanks
-Brent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to