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/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to