Skip to main content
Hedge
Inspiring
December 10, 2010
Answered

cfselect not showing cfc bound data

  • December 10, 2010
  • 3 replies
  • 8921 views

I have a CFC that works fine. I can access it directly and get data etc. I even have it working find on another server with the same datasource. I am binding the cfc to a cfselect like so.

<cfform>

<cfselect name="category" bind="cfc:cfc.GetCategory.getCategory()" bindonload="true"></cfselect>

</cfform>

My cfc is located in a directory name cfc. The name is GetCategory.cfc and the method is getCategory. I an access it fine by goign to the URL as so.

http://siteurl/cfc/GetCategory.cfc?method=getCategory

It displays the data fine.

However when I try to look at the page the cfselect is on it shows me an empty drop down box with no selections. I can see using the cfdebug in the url that the cfc is being executed properly and returning data. It is just not showing up in the drop down. 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? Keep in mind this code is working fine on another CF9 machine with a very similar setup.

    This topic has been closed for replies.
    Correct answer ilssac

    Ok I think I found the issue but have no idea why it is doing this. I have an include in my application.cfm file that handled the cookie security for the admin folder. When I comment out the include the cfc binds the data like it should to the cfselects. Here is the contents of the CFINCLUDE any idea why this would cause the CFC not to bind data to teh CFSELECT tags?

    <!-- Check to see if these cookies are on the client machine -->
    <CFIF IsDefined("COOKIE.Password") AND IsDefined("COOKIE.Email")>
    <!-- If the cookies are not found then do nothing -->
    <CFELSE>
    <!-- Check for the LEmail and LPassword form fields to see if they have been passed -->
    <CFIF IsDefined("FORM.LEmail") AND IsDefined("FORM.LPassword")>
        <!-- Authenticate the LEmail and LPassword against the Email and Password fields in the Passwords table -->
        <CFQUERY DATASOURCE="#DataSource#" NAME="Check">
        SELECT * FROM Passwords
        WHERE Email = '#FORM.LEmail#' AND Password = '#cfusion_encrypt(FORM.LPassword, ccKey)#'
        </CFQUERY>
    <!-- If no matches are found display this code -->
    <CFIF #Check.RecordCount# IS 0>
        <font size="+1" color="Red"><b><div align="CENTER">Invalid Login Credentials</div></b></font>
        <CFINCLUDE TEMPLATE="index.cfm">
    <CFABORT>
    <CFELSE>
        <!-- If a match is found then assign the 2 cookies below -->
        <CFCOOKIE NAME="Email" VALUE="#FORM.LEmail#" EXPIRES="30">
        <CFCOOKIE NAME="Password" VALUE="#cfusion_encrypt(FORM.LPassword, ccKey)#">
    </CFIF>
    <!-- If none of the above occours then force the client to authenticate -->
    <CFELSE>
    <font size="+1" color="Red"><b><div align="CENTER">You Must Login Below</div></b></font>
    <CFINCLUDE TEMPLATE="index.cfm">
    <CFABORT>
    </CFIF>
    </CFIF>


    Whitespace?

    What happens if you wrap the include code in <cfsilent>...</cfsilent tags.

    3 replies

    Hedge
    HedgeAuthor
    Inspiring
    December 14, 2010

    Ok another interesting factoid. It can't be server related because I moved a copy of the cfm containing the cfform and the cfc to another site omn the same server and it works fine. See the following.

    http://www.securepurchasing.net/tempx.cfm

    so this would lead me to belive it is a setting with this one particular site somehow.

    BKBK
    Community Expert
    Community Expert
    December 14, 2010

    Oh, don't forget to add the attibutes value="id" display="category"  to the cfselect tag.

    Hedge
    HedgeAuthor
    Inspiring
    December 14, 2010

    It worked without it on both the other sites. When I add it to this site it still doesn't work

    Inspiring
    December 14, 2010

    Keep in mind this code is working fine on another CF9 machine with a very similar setup.

    "Similar".

    What are the differences?  Start with the differences in CFAdmin... what are they?  Do a side-by-side compare of each screen, and what are the differences?

    --

    Adam

    Hedge
    HedgeAuthor
    Inspiring
    December 14, 2010

    I did a side by side and see no differences. The only difference I see is the server where it is not working has a newer version. You would think that would be the opposite.

    Both servers report running 9,0,1,274733

    However on the server where the binding is working fine the jre is running the older jre because when we upgraded to 9.01 cf would not start so the hosting company had to use this as a setting.

    Java Home                       C:\ColdFusion9\runtime\jre_installerbackup

    On the server where it is working it has this setting.

    Java Version                        1.6.0_14

    On the server where it is not working it has this setting.

    Java Version                        1.6.0_17 

    On the server that upgraded to 9.01 with no problems with the newer JRE is where the binding is not happening.

    BKBK
    Community Expert
    Community Expert
    December 12, 2010

    Add the value and display attributes to the cfselect tag. Here is an example to illustrate. It uses the datasource cfdocexamples which ships with Coldfusion, so you don't need to configure anything.

    Employee.cfc

    <cfcomponent output="false">
    <cffunction name="getEmployee" access="remote" output="false" returntype="query">
    <cfset var getAllEmployees = queryNew("","")>
    <cfquery name = "getAllEmployees" dataSource = "cfdocexamples">
        SELECT Emp_ID,  FirstName || ' ' || LastName as EmployeeName
        FROM Employees
    </cfquery>
    <cfreturn getAllEmployees>
    </cffunction>
    </cfcomponent>

    (within the same directory)

    selectEmployee.cfm

    <cfform>

    <cfselect value="emp_id" display="EmployeeName" name="employee" bind="cfc:Employee.getEmployee()" bindonload="true"></cfselect>

    </cfform>

    Hedge
    HedgeAuthor
    Inspiring
    December 12, 2010

    I tried adding that but it didn't make any difference. Still no data in the drop down menus.

    BKBK
    Community Expert
    Community Expert
    December 12, 2010

    What type of data is does getCategory() return?


    added edit: Make sure getCategory() returns a query.

    Message was edited by: BKBK