user2271384
user2271384

Reputation: 21

cfselect not binding to cfc

I'm new to the newer versions of ColdFusion and I'm having issues with a simple databind to a cfselect. I've done my best to thoroughly research it and I've even gone back to a textbook and essentially duplicated the code example in a test file and I still get the same error.

I'm trying to build the common situation where there are 2 cfselects and the second is dependent on the first, but at this point, I can't even get the first to work. The error returned is:

"Bind failed for select box Species_id, bind value is not a 2D array or valid serialized query"

Thanks in advance for any help. Here is the code:

<cfcomponent>
    <cffunction name="getSpecies" access="remote" returnType="array">
    <cfset var rsData = "">
    <cfset var myReturn=ArrayNew(2)>
    <cfset var i=0>
      <cfstoredproc datasource="#application.dsn#" procedure="up_get_Species">
            <cfprocresult name="DataResults">
        </cfstoredproc>
    <cfloop query="DataResults">
        <cfset myReturn[rsData.currentRow][1]=rsData.Species_id>
        <cfset myReturn[rsData.currentRow][2]=rsData.Species>
    </cfloop>
    <cfreturn myReturn>
    </cffunction>
</cfcomponent>

<html>
<head>
    <title>CFSelect Example</title>
</head> 
<body>
<h1>Sandbox for getting cfselect bind working</h1>
<cfform name="form1">
Wood Type
<br>
<cfselect name="Species_id" bind="office.cfc:data.getspecies()"
    bindOnLoad = "true" />
</cfform>
</body>
</html>

Upvotes: 2

Views: 2866

Answers (1)

Leigh
Leigh

Reputation: 28873

It looks like your bind syntax is off. The bind expression should start with the type: of bind (cfc, url, javascript). Since you are binding to a component, you must preface it with "cfc:", ie

     bind="cfc:path.to.yourComponentName.yourFunctionName()"

That said, later versions of CF support binding to a query, which simplifies binding. Just change the function returnType to query.

<cffunction name="getSpecies" access="remote" returnType="query">
     <!--- Be sure to Local scope all variables, including query names --->
     <cfstoredproc datasource="#application.dsn#" procedure="up_get_Species">
          <cfprocresult name="Local.DataResults">
     </cfstoredproc>

     <cfreturn Local.DataResults >
</cffunction>

Then specify the display and value attributes in your select list.

<cfselect name="service" 
          bind="cfc:office.cfc:data.getSpecies()"
          display="Species"
          value="Species_id" ...>

Upvotes: 2

Related Questions