Professional Web Applications Themes

Update CFC Help Please - Coldfusion - Advanced Techniques

I'm brand new to CFC and OO, so I'm having trouble with what I think should be very simple. Basically, I am invoking a cfc to create a Campaign object. Then, I want to set a couple of values and call the cfc again to save the campaign. Here is a simplified version of my code: Calling Page: <cfscript> thisCampaign = CreateObject("component","shared.common.campaign") .init(); thisCampaign.campaignName = "brian"; saveIt = thisCampaign.saveCampaign(); </cfscript> Campaign.cfc <cfcomponent> <cffunction name="init" access="public" returntype="campaign"> <cfreturn this /> </cffunction> <cffunction name="saveCampaign" access="public" returntype="any"> <cfstoredproc datasource="mydsn" procedure="proc_Campaign"> <cfprocparam cfsqltype="cf_sql_varchar" dbvarname="CampaignName"value="#this.campaignName #"> </cfstoredproc> <cfset thisResult = cfstoredproc.result> <cfreturn thisResult /> </cffunction> ...

Sponsored Links
  1. #1

    Default Update CFC Help Please

    I'm brand new to CFC and OO, so I'm having trouble with what I think should be
    very simple. Basically, I am invoking a cfc to create a Campaign object.
    Then, I want to set a couple of values and call the cfc again to save the
    campaign. Here is a simplified version of my code:

    Calling Page:
    <cfscript>
    thisCampaign = CreateObject("component","shared.common.campaign") .init();
    thisCampaign.campaignName = "brian";
    saveIt = thisCampaign.saveCampaign();
    </cfscript>


    Campaign.cfc
    <cfcomponent>

    <cffunction name="init" access="public" returntype="campaign">
    <cfreturn this />
    </cffunction>

    <cffunction name="saveCampaign" access="public" returntype="any">
    <cfstoredproc datasource="mydsn" procedure="proc_Campaign">
    <cfprocparam cfsqltype="cf_sql_varchar"
    dbvarname="CampaignName"value="#this.campaignName #">
    </cfstoredproc>
    <cfset thisResult = cfstoredproc.result>
    <cfreturn thisResult />
    </cffunction>

    </cfcomponent>

    My questions are: can I set the values this way and then call the saveCampaign
    method, and if so, how do I reference those values in the cfprocparam tags in
    the method. I'm getting an error java.lang.NullPointerException in the cfc



    Sponsored Links
    bburkettaz Guest

  2. #2

    Default Re: Update CFC Help Please

    If your cfc is going to do nothing but run a stored procedure and return the
    query results, you don't need an init method. You just need the savecampaign
    method, with one argument.

    You could then call it with the cfinvoke tag. Something like this:

    <cfinvovke component = "campaign" method="savecampaign"
    campaignname="brian" returnvariable="saveit">

    If you are going to add more functions, then we can talk init functions.

    Originally posted by: bburkettaz
    I'm brand new to CFC and OO, so I'm having trouble with what I think should be
    very simple. Basically, I am invoking a cfc to create a Campaign object.
    Then, I want to set a couple of values and call the cfc again to save the
    campaign. Here is a simplified version of my code:

    Calling Page:
    <cfscript>
    thisCampaign = CreateObject("component","shared.common.campaign") .init();
    thisCampaign.campaignName = "brian";
    saveIt = thisCampaign.saveCampaign();
    </cfscript>


    Campaign.cfc
    <cfcomponent>

    <cffunction name="init" access="public" returntype="campaign">
    <cfreturn this />
    </cffunction>

    <cffunction name="saveCampaign" access="public" returntype="any">
    <cfstoredproc datasource="mydsn" procedure="proc_Campaign">
    <cfprocparam cfsqltype="cf_sql_varchar"
    dbvarname="CampaignName"value="#this.campaignName #">
    </cfstoredproc>
    <cfset thisResult = cfstoredproc.result>
    <cfreturn thisResult />
    </cffunction>

    </cfcomponent>

    My questions are: can I set the values this way and then call the saveCampaign
    method, and if so, how do I reference those values in the cfprocparam tags in
    the method. I'm getting an error java.lang.NullPointerException in the cfc





    Dan Guest

  3. #3

    Default Re: Update CFC Help Please

    Thanks Dan. Actually, the cfc contains about 10 functions related to
    campaigns. The saveCampaign method is just the one that's giving me problems.
    I've identified that I can do this: thisCampaign.campaignName = "brian"; (I
    cfdumped thisCampaign). What I don't know is how to reference that value
    inside one of the methods. Do I use this.campaignName,
    thisCampaign.campaignName or what?

    bburkettaz Guest

  4. #4

    Default Re: Update CFC Help Please

    This is my approach. It ain't exactly OOP, but it works when I code it.
    For all the variables you want to be available to more than one function, make
    them properties.
    Have your init method accept all the relevent arguments, set values to all the
    properties, and return true if successful, false if not.
    Have all your other arguments accept no arguments. Use the properties instead.

    In your calling template do this:
    <cfobject component="campaign" name = "abc">
    <cfscript>
    args=structnew();
    args.a="something";
    args.b = "something else";
    more of this as required.

    x = abc.init(argumentcollection = args);
    y = abc.anothermethod();
    </cfscript>


    Originally posted by: bburkettaz
    Thanks Dan. Actually, the cfc contains about 10 functions related to
    campaigns. The saveCampaign method is just the one that's giving me problems.
    I've identified that I can do this: thisCampaign.campaignName = "brian"; (I
    cfdumped thisCampaign). What I don't know is how to reference that value
    inside one of the methods. Do I use this.campaignName or do I have to use
    cfarguments and pass the values to the cfc instead of setting the way I'm
    trying?



    Dan Guest

  5. #5

    Default Re: Update CFC Help Please

    Thanks Dan, I'll give that a try.
    bburkettaz Guest

Similar Threads

  1. why is the "Adobe Acrobat 6.0.1 Update" message there at the top? -- the update doesn't work
    By john_cummin@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 6
    Last Post: August 5th, 01:51 PM
  2. 5.0.7 Update Pack 1 requires SCO Update license?
    By Scott McMillan in forum SCO
    Replies: 0
    Last Post: July 30th, 08:04 PM
  3. Specifying "do not update" values in "additive" UPDATE sprocs
    By Joel Thornton in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: June 30th, 10:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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