Home | Projects | Downloads | Contact Me | SQL Injection Attacks

Referencing CFC methods through structures

It took me a while to finally decide on a name for this post.  In my ExplorerG3 Agency Management System I need to access several databases depending on the type of insurance coverage a client has.  Before, I had a separate search page for each  type of policy, in this case automobile or anything other than automobile.  This is not so bad if you are just looking through one type of policy, but it requires maintaining several search pages and any time I make a change I need to update them all.  I would rather update one file and be done with it.

With that in mind, I designed a new search page this morning.  The first thing I needed to do was to get all my data prepared:

<!--- Set our default data providers --->   
<cfscript>
    searchProviders=ArrayNew(1);

    tempData=structNew();
    tempData.Name="Auto";
    tempData.com=application.auto;
    tempData.dataHandler="/_autopath/_search/client.cfm";
    tempData.ds=8000;
    x=ArrayAppend(searchProviders,tempData);

    tempData=structNew();
    tempData.Name="Other";
    tempData.com=application.other;
    tempData.dataHandler="/_otherpath/_search/client.cfm";
    tempData.ds=8300;
    x=ArrayAppend(searchProviders,tempData);   
</cfscript>

This creates an array for me to store my data providers.  The Auto component receives all of its information using web services to connect to a remote server.  The Other component is connected to a Coldfusion data source.

The initialization script is pretty self-explanatory.  The Name member is the name that will be shown on the Spry tabbed-panel tab when the data is displayed, the com member is a reference to the instanced-based component in the application scope,  the dataHandler member contains the page to view the client, and finally the ds member tells it which office to poll.

The next step, is to load the queries so we can actually do something with them:

<cfset rSet=ArrayNew(1)>
<cfloop from="1" to="#arrayLen(searchProviders)#" index="ndx">
    <cfset temp=structNew()>
    <cfset temp.Query=searchProviders[ndx].com.searchClients(term=url.term,field=url.SearchField,ds=searchProviders[ndx].ds)>
    <cfset x=arrayAppend(rSet,temp)>
</cfloop>

This creates an array named rSet that will hold the results.  Then I loop through the dataProviders array and store the query results by referencing the "pointer" to the CFC through the com structure member.  In order to add another searchProvider the only thing I have to do is to add it in my initialization script and I do not have to worry about editing multiple search files any more. 

Comments
Layout: Shane Zehnder ::: BlogCFC was created by Raymond Camden. ::: This blog is running version 5.9.