Oliver Codewell
Oliver Codewell

Reputation: 1

How To Share Query Data Between Two ColdFusion CFCs?

I am creating a CFC called "core_appdata". This CFC will hold the core stored procedures for an application. Example....

    <cfcomponent displayname="core_appdata" hint="I Return Core App Data" output="no">
    <cffunction name="getprogram_list">

  <cfargument name="getstoredproc_input_campaignid" type="string" required="false">
   <cfargument name="getstoredproc_input_filtertestrecs" type="string" required="false">
    <cfargument name="getstoredproc_input_startdate" type="date" required="false">
    <cfargument name="getstoredproc_input_enddate" type="date" required="false">
    <cfargument name="getstoredproc_input_listtypeid" type="string" required="false">
    <cfargument name="getstoredproc_input_listid" type="string" required="false">
    <cfargument name="getstoredproc_input_appenvr" type="string" required="false">

    <cfset var rst_getprogram_list ="">
     ---  stored proc ---            
         <cfstoredproc procedure  = "p_adb_getprogram_list">
         </cfstoredproc>

    <cfreturn rst_getprogram_list />
   </cffunction>
    </cfcomponent> 

I would also like to create a CFC called "core_appdata_grids". This CFC would be used to bind to cfgrids and allow paging etc. In a perfect world, this CFC would get its data from the method/function "getprogram_list" in the CFC "core_appdata" above. Example...

    <cfcomponent displayname="core_appdata_grids" hint="I Return Core App Data For CFGrids " output="no">

    <cffunction name="getprogram_list_grid">

               <cfargument name="page" required="no" />
        <cfargument name="pageSize" required="no" />
        <cfargument name="gridsortcolumn" required="no" />
        <cfargument name="gridsortdirection" required="no" />   
        <cfargument name="getstoredproc_input_campaignid" type="string" required="false">
               <cfargument name="getstoredproc_input_filtertestrecs" type="string" required="false">
               <cfargument name="getstoredproc_input_startdate" type="date" required="false">
               <cfargument name="getstoredproc_input_enddate" type="date" required="false">
               <cfargument name="getstoredproc_input_listtypeid" type="string" required="false">
               <cfargument name="getstoredproc_input_listid" type="string" required="false">
                <cfargument name="getstoredproc_input_appenvr" type="string" required="false">

        <cfset var rst_getprogram_list_grid ="">
         ---  get data ---           


        <cfreturn queryconvertforgrid(rst_getprogram_list_grid, page, pagesize) />
    </cffunction>

     </cfcomponent>

Questions:

Thank you in advance for your time in helping me with this question.

OC

Upvotes: 0

Views: 274

Answers (2)

Nicklepedde
Nicklepedde

Reputation: 565

If you don't want to extend the CFC, especially if that's not being true to your model, you could just call the other CFC:

<cfset var rst_getprogram_list_grid = createObject("component","core_appdata").getprogram_list() />

OR even better somewhere above it all set:

<cfset request.core_appdata=createObject("component","core_appdata")>

And then in your CFC:

<cfset var rst_getprogram_list_grid = request.core_appdata.getprogram_list() />

Just a few options.

Upvotes: 1

Paul
Paul

Reputation: 1575

I can't see the name of the cfc that produces the grid but just extend the base cfc which will inherit all the methods.

<cfcomponent extends="core_appdata">

<cffunction name="getprogram_list_grid">
    <cfargument name="page" required="no" />
    <cfargument name="pageSize" required="no" />
    <cfargument name="gridsortcolumn" required="no" />
    <cfargument name="gridsortdirection" required="no" />   
    <cfargument name="getstoredproc_input_campaignid" type="string" required="false">
    <cfargument name="getstoredproc_input_filtertestrecs" type="string" required="false">
    <cfargument name="getstoredproc_input_startdate" type="date" required="false">
    <cfargument name="getstoredproc_input_enddate" type="date" required="false">
    <cfargument name="getstoredproc_input_listtypeid" type="string" required="false">
    <cfargument name="getstoredproc_input_listid" type="string" required="false">
    <cfargument name="getstoredproc_input_appenvr" type="string" required="false">

    <cfset var rst_getprogram_list_grid = super.getprogram_list() />

    <cfreturn queryconvertforgrid(rst_getprogram_list_grid, page, pagesize) />
</cffunction>

</cfcomponent>

Upvotes: 2

Related Questions