Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
manik_1 #1
Java variable NULL values
Hi
In my Java value object, some times String variables are coming NULL. That time, in CFM, it's giving undefined error. Please tell me how to solve this.
Regards
Santhosh
manik_1 Guest
-
cfgridupdate and null values
Yeah I have the same problem. It looks like the only solution is to rewrite a custom version cfgridupdate to do my own custom query update. I... -
Please HELP! Problem with NULL values...
Hey everyone! I'm developing an asp/VBScrpti/Access web site and I'm having a little trouble with the record sets SQL. The site's deadline is... -
Null Values
hi how to count null values in an array? tnx -
Null values enter to SQL
Hi, I have datagrid filled using SqlDataAdapter. One of the fields is a date field which can be null. When I assign null value I receive the... -
Joining on Null values
Hello everyone Have a problem that I need help with I have a table Codes which looks like: ID, Code, modifier Any code can have multiple... -
PaulH #2
Re: Java variable NULL values
you'll need to test if that cf var exists if you have a java method returning nulls.
if (isDefined("varFromJava"))
varFromJava="";
PaulH Guest
-
manik_1 #3
Re: Java variable NULL values
Hi,
Thanks for reply.
I have done that. But even though I'm getting error.
I have class in Java like this
class Address{
String address1;
String address2;
}
I'm getting this address object through session.
when I print this object like this I'm getting error
<cfif isdefinied(addressObj1)>
<cfif isdefinied(addressObj1.address1)>
<cfoutput>#addressObj1.address1#
</cfoutput>
</cfif>
Please give me your suggestion.
Thanks
Santhosh
</cfif>
manik_1 Guest
-
-
mxstu #5
Re: Java variable NULL values
Check PaulH's original example and make sure you're spelling the function name correctly IsDefined and that you have used quotes around the variable name
IsDefined("addressObj1")
mxstu Guest
-
manik_1 #6
Re: Java variable NULL values
I'm getting that Address object through session
Here is the code
<cfset addressObj1 = GetPageContext().getSession.getAttribute("addressV alue")/>
<cfif isdefined(addressObj1)> //This line is working fine.
<cfif isdefined(addressObj1.address1)> // Problem is with this checking. Even
though the address1 is null, it is going inside.
<cfoutput>#addressObj1.address1#
</cfoutput>
</cfif>
</cfif>
manik_1 Guest
-
manik_1 #7
Re: Java variable NULL values
I'm getting that Address object through session
Here is the code
<cfset addressObj1 =
GetPageContext().getSession().getAttribute("addres sValue")/>
<cfif isdefined(addressObj1)> //This line is working fine.
<cfif isdefined(addressObj1.address1)> // Problem is with this checking. Even
though the address1 is null, it is going inside.
<cfoutput>#addressObj1.address1#
</cfoutput>
</cfif>
</cfif>
manik_1 Guest
-
PaulH #8
Re: Java variable NULL values
as mxstu pointed out, you're missing the quotes in the isDefined() function.
PaulH Guest
-
manik_1 #9
Re: Java variable NULL values
I'm sorry I have missed quotes here, but in the code we are using that..
I just updated the code
<cfset addressObj1 =
GetPageContext().getSession().getAttribute("addres sValue")/>
<cfif isdefined("addressObj1")> //This line is working fine.
<cfif isdefined("addressObj1.address1")> // Problem is with this checking.
Even though the address1 is null, it is going inside.
<cfoutput>#addressObj1.address1#
</cfoutput>
</cfif>
</cfif>
Please give me suggestion. Where I went wrong
manik_1 Guest
-
manik_1 #10
Re: Java variable NULL values
Hi
I think I got some work around answer. Please let me know, is this correct.
In Data Object, we need to have get and set method for all variables.
class Address{
String address1;
String address2;
public String getAddress1(){
return address1;
}
public void setAddress1(String address1){
this.address1 = address1;
}
public String getAddress2(){
return address1;
}
public void setAddress2(String address2){
this.address2 = address2;
}
}
in the CFM we have to do like this
<cfif isdefined("addressObj1")>
<cfset address1 = addressObj1.getAddress1()/>
<cfif isdefined("address1")>
<cfoutput>#address1#</cfoutput>
</cfif>
</cfif>
This works fine. But my question here is will this hit the performance?
manik_1 Guest
-
OldCFer #11
Re: Java variable NULL values
You need to understand InDefined(). It means has it been defined, ie set.
Whether it is
null or empty is immaterial. Your code:
<cfif isdefined("addressObj1")>
<cfset address1 = addressObj1.getAddress1()/>
<--- Of course Address1 is defined! You just set (defined) it in he line
above. --->
<cfif isdefined("address1")>
<cfoutput>#address1#</cfoutput>
</cfif>
</cfif>
OldCFer Guest
-
PaulH #12
Re: Java variable NULL values
larry, actually if addressObj1.getAddress1() is a java object and it spat out a
NULL, address1 would "go south" as far as cf is concerned. if you have cf7, try
that w/javacast("null","") to see what i mean.
PaulH Guest
-
OldCFer #13
Re: Java variable NULL values
You're right. I haven't run across that yet, so I shouldn't jump in with both feet.
OldCFer Guest



Reply With Quote

