Skip to main content
Known Participant
September 24, 2012
Question

Bind with CFSelect Not Showing Data

  • September 24, 2012
  • 4 replies
  • 8244 views

I have a CFC that I can access directly and get data. I am binding the cfc to a cfselect like so.

<cfform>

<cfselect name="category" bind="cfc:cfcs.menusdata.getData()" bindonload="true"></cfselect>

</cfform>

My cfc is located in a directory named cfcs at the application root. The name is menudata.cfc and the method is getData. I can access it fine by goign to the URL as so.

http://siteurl/cfcs/menudata.cfc?method=getData

It displays the data fine:
DinnerFridayMondaySaturdaySundayThursdayTuesdayWednesday

However when I try to look at the page the cfselect is on it shows me an empty drop down box with no selections. The function is just a simple query that return the records. Here is my cfc:

<cfcomponent>

<cffunction name="getData" access="remote" returntype="query" output="yes">

   

    <cfset var q = "">

   

    <cfquery name="q" datasource="ezpay">

    select description

    from service_descriptions

    </cfquery>

   

  <cfreturn q>

</cffunction>

</cfcomponent>

I have been banging my head against this one for a few days now so any outside eyes would be helpful. Anybody else run into this issue where the cfc works fine but does not appear to be binding to the cfselect for whatever reason? ColdFusion 8 is my server.

Many thanks.

-Brian

    This topic has been closed for replies.

    4 replies

    itisdesign
    Inspiring
    September 27, 2012

    Hi Brian,

    If there is in fact a bug, then it'd be good to determine what it is.  Could you please verify if the following throws the same error?

    index.cfm

    -----------

    <cfform>

    <cfselect name="category" bind="cfc:cfcs.menudata.getData()" bindonload="true" value="description" />

    </cfform>

    menudata.cfc

    -----------

    <cfcomponent>

    <cffunction name="getData" access="remote" returntype="query" output="yes">

      <cfset var q = "">

      <cfscript>

        q = queryNew("description", "varchar");

        queryAddRow(q, 8);

        querySetCell(q, "description", "Dinner", 1);

        querySetCell(q, "description", "Monday", 2);

        querySetCell(q, "description", "Tuesday", 3);

        querySetCell(q, "description", "Wednesday", 4);

        querySetCell(q, "description", "Thursday", 5);

        querySetCell(q, "description", "Friday", 6);

        querySetCell(q, "description", "Saturday", 7);

        querySetCell(q, "description", "Sunday", 8);

      </cfscript>

      <cfreturn q>

    </cffunction>

    </cfcomponent>

    Just try exactly that.  If these two files still produce the same issue, and if there is an Application.cfm/cfc, then try commenting out the code w/in it and try these two files again.

    Thanks,

    -Aaron

    Known Participant
    September 27, 2012

    Thanks Aaron,

    I tried your initial code exactly and had the same result, empty select.

    I then commented out everything in the application.cfm file and had the same result also. HEre is my AJAX debug output:

    info:http: CFC invocation response:                 {"COLUMNS":["DESCRIPTION"],"DATA":[["Dinner"],["Monday"],["Tuesday"],["Wednesday"],["Thursday"],["Friday"],["Saturday"],["Sunday"]]}

    info:http: HTTP GET /serviceticket/cfcs/menudata.cfc?method=getData&returnFormat=json&argumentCollection=%7B%7D&_cf_nodebug=true&_cf_nocache=true&_cf_rc=0

    info:http: Invoking CFC: /serviceticket/cfcs/menudata.cfc , function: getData , arguments: {}

    info:LogReader: LogReader initialized

    info:global: Logger initialized

    -Brian

    Known Participant
    September 27, 2012

    Hold on, nevermind.

    I initially commented out just the contents of the body tag in my application.cfm file. After my last post, I actually commented out everything in the file and it is now working.

    Here is what my application.cfm file looks like. Not too much going on, just processing the login logic mainly.

    ==============

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Jaydien Network Solutions - Service Ticketing System</title>

    </head>

    <body>

    <!--- Set application name and enable Client and Session variables. (days, hours, minutes, seconds) --->

    <cfapplication name="ServiceTicket"

        clientmanagement="Yes"

        sessionmanagement="Yes"

        scriptprotect="Yes"

        setdomaincookies="no"

        sessiontimeout="#CreateTimeSpan(0,0,90,0)#"

        applicationtimeout="#CreateTimeSpan(1,0,0,0)#">

    <!---Error handling    

    <cferror type="exception" template="error_handling/error.cfm"> <!---Normal errors --->

    <cferror type="request" template="error_handling/error_request.cfm"> <!---Serious errors --->--->

       

       <!--- Now define that this user is logged out by default --->

       <CFPARAM NAME="session.allowin" DEFAULT="false" />

      

       <!--- Now define this user id to zero by default, this will be used later on to access specific information about this user. --->

       <CFPARAM NAME="session.userid" DEFAULT="0" />

      

       <!--- Now if the variable "session.allowin" does not equal true, send user to the login page --->

       <!--- the other thing you must check for is if the page calling this application.cfm is the "login.cfm" page and the "Login_process.cfm" page since the Application.cfm is always called, if this is not checked the application will simply Loop over and over. To check that, you do the following call --->

      

       <cfif session.allowin neq "true">

           <cfif  ListLast(CGI.SCRIPT_NAME, "/") EQ "index.cfm">

           <cfelseif ListLast(CGI.SCRIPT_NAME, "/") EQ "login_action.cfm">

           <cfelse>

               <!--- this user is not logged in, alert user and redirect to the login.cfm page --->

              

               <cflocation url="index.cfm?error=1">

              

           </cfif>

       </cfif>     

    </body>

    </html>

    12Robots
    Participating Frequently
    September 25, 2012

    My usual advice is not to use cfform (for anything), but I'll offer this.

    I see in this example from Dan Short (http://www.dansshorts.com/post/cfselect-binding-and-selectedvalues) that he is specifying which columns to use for the "value" and "display" of the list. I don't see you doing that. It looks like since you are only returning a single value you could get away with *just* specifying the value.

    <cfselect name="category" bind="cfc:cfcs.menudata.getData()" bindonload="true" value="description"></cfselect>

    Hope that helps.

    Jason

    Known Participant
    September 25, 2012

    Thanks I'll try that and post my results. What would you use besides <cfform> ?

    12Robots
    Participating Frequently
    September 25, 2012

    HTML forms combined with jQuery or another JS library (prototype, Mootools, Dojo, etc).

    jason

    Miguel-F
    Inspiring
    September 25, 2012

    Hopefully this is just a typo in your post here but you state that your cfc is named 'menudata.cfc'.  The sample code of your cfselect statement is calling 'menusdata' (with an s).

    Known Participant
    September 25, 2012

    Yes just a typo in my post.

    Known Participant
    September 25, 2012

    Nobody has any suggestions? Come on, there must be something that I can try.

    -Brian