views:

72

answers:

1

Hello:

I have a CFC with a remote function and am trying to populate it into my cfm page's cfselect element. But I am not getting anything in the select.

I tried executing the cfc directly, but the method that I call does not execute.

Here is the code for the CFC:

    <cfcomponent output="false">
     <cffunction name="getYear" access="remote" returnType="query">

      <cfset yearlist = QueryNew("yr","integer")>
      <cfset temp = QueryAddRow(yearlist,3)>
      <cfset counter = 1>
      <cfloop from="#evaluate(year(Now())-1)#" to="#evaluate(year(Now())+1)#" index="y">
       <cfset temp = QuerySetCell(yearlist,"yr",y,counter)>
       <cfset counter = counter + 1>
      </cfloop>

      <cfreturn yearlist>
     </cffunction>
</cfcomponent>

Here is the code for the CFM

    <body>

    <cfform>

    <table>
     <tr>
      <td>Select Year:</td>
      <td><cfselect name="yearval"
         bind="cfc:cfc.ajaxcomp.getYear()"
         value="yr"  
         display="yr"
         bindonload="true" /></td>
     </tr>
    </table>

    </cfform>

</body>

Could you please tell me what am I missing here?

Thanks!

+1  A: 

So the following code works for me. I changed a few things, so hard to know what did it but:

  1. Var-scoped the variables
  2. Removed some complexity
  3. Changed the query column from integer to varchar

-

<cfcomponent output="false">
    <cffunction name="getYear" access="remote" returnType="query">

        <cfset var y = 0 />
        <cfset var yearList = QueryNew("yr","varchar")>

        <cfloop from="#year(Now())-1#" to="#year(Now())+1#" index="y">
            <cfset queryAddRow(yearList) />
            <cfset QuerySetCell(yearList,"yr",y)>
        </cfloop>

        <cfreturn yearlist>
    </cffunction>
</cfcomponent>
Terry Ryan