Java variable NULL values

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. Null Values
      hi how to count null values in an array? tnx
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default Re: Java variable NULL values

    show how you init the java object in cf.
    PaulH Guest

  6. #5

    Default 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

  7. #6

    Default 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

  8. #7

    Default 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

  9. #8

    Default Re: Java variable NULL values

    as mxstu pointed out, you're missing the quotes in the isDefined() function.

    PaulH Guest

  10. #9

    Default 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

  11. #10

    Default 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

  12. #11

    Default 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

  13. #12

    Default 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

  14. #13

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139