Brad Wood wrote:

> What's the best way to test for a Java NULL in CF?

> Should I just set the output of each of those methods into a variable,
> and then check for the variables existence?

That'll work.

<cfset path=my_url.getpath()/>
<cfif isdefined('path')> <!--- ... ---> </cfif>

We use a little Java class to tidy this (amongst other things) up that
I've attached - with luck the houseoffusion mailing list software will
leave it intact.

There are a few bits glued into the server scope at the CF end:

 <cfscript>
  server.undefined=createobject('java',
'horus.coldfusion.undefined').init();

  function defined( value ) {
    var argc=arguments.size();
    value=server.undefined.assigned(value);
    if (argc eq 1) return value;
    if (value) return arguments[2];
    if (argc gt 2) return arguments[3];
    return '';
  }

  server.defined=defined;
 </cfscript>

Using your my_url object, you could then do:

<cfdump var=#server.undefined.check(my_url.getpath(), 'NULL!')#/>

or

<cfset path=server.undefined.check(my_url.getpath())/>

<cfif server.defined(path)>
 <!--- foo --->
<cfelse>
 <!--- bar --->
</cfif>

It's worth noting that the "check" method must be called directly, with
the potentially-null-returning Java call as an argument; that's the only
way to bypass ColdFusion bleating about an undefined variable.

Having a NULL-surrogate value that can be used anywhere in ColdFusion is
*hugely* useful; I only wish that Macradobaire had seen fit to do it
properly in the first place.

-- 
Regards,

Pete Jordan
Horus Web Engineering Ltd
http://www.webhorus.net/
phone: +44 1275 543971
mobile: +44 7973 725120


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:308065
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to