EasyCFM.COM ColdFusion Forums / General Discussion / using CFC's

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: using CFC's

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

AaronMoss
02-12-2013 @ 12:29 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Member
Posts:
Joined: Aug 2012

Hello Everyone,

I'm trying to get a related select working using Ben Forta's example:http://forta.com/blog/index.cfm/2007/5/31/ColdFusion-Ajax-Tutorial-2-Related-
Selects

We are a car part manufacture re building our YYM search. We host on a CF8 platform. I have tried using jquery but have lost a good 2 days trying
to get that one to jive.

I have never used a cfc, but it seems like the coldfusion page isn't including it.

Here is the CFC code:
<cfcomponent output="true">

    <!--- Get array of media types --->
    <cffunction name="getMedia" access="remote" returnType="array">
        <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(2)>
        <cfset var i=0>

        <!--- Get data --->
        <cfquery name="data" datasource="GriffinDSN" >
        SELECT ID, PartNumber
        FROM ExactFit2012
        ORDER BY PartNUmber
        </cfquery>

        <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[1]=data.ID>
            <cfset result[2]=data.PartNumber>
        </cfloop>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>

    <!--- Get art by media type --->
    <cffunction name="getArt" access="remote" returnType="array">
        <cfargument name="mediaid" type="numeric" required="true">

        <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(2)>
        <cfset var i=0>

        <!--- Get data --->
        <cfquery name="data" datasource="GriffinDSN" >
        SELECT ID, PartNumber
        FROM VehicleApps
        WHERE PartNumber = #ARGUMENTS.PartNumber#
        ORDER BY PartNumber
        </cfquery>
    
        <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[1]=data.ID>
            <cfset result[2]=data.PartNUmber>
        </cfloop>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>

</cfcomponent>

Here is the form:
<cfform>

<table>
    <tr>
        <td>Select Media Type:</td>
        <td><cfselect name="mediaid"
                bind="cfc:related.getMedia()"
                bindonload="true" /></td>
    </tr>
    <tr>
        <td>Select Art:</td>
        <td><cfselect name="artid"
                bind="cfc:related.getArt({mediaid})" /></td>
    </tr>
</table>

</cfform>

I have saved the cfc in a folder called cfc, as well as in the root with the form.

Thank you very much for your time,
Aaron

This message was edited by AaronMoss on 2-12-13 @ 12:30 PM


Website Designed and Developed by Pablo Varando.