• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfselect not showing cfc bound data

Contributor ,
Dec 10, 2010 Dec 10, 2010

Copy link to clipboard

Copied

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.

Views

7.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Dec 20, 2010 Dec 20, 2010

Whitespace?

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

Votes

Translate

Translate
Community Expert ,
Dec 12, 2010 Dec 12, 2010

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 12, 2010 Dec 12, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2010 Dec 12, 2010

Copy link to clipboard

Copied

What type of data is does getCategory() return?


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

Message was edited by: BKBK

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 12, 2010 Dec 12, 2010

Copy link to clipboard

Copied

returnType="array"

This code works on another 9.0 server. Weird.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 12, 2010 Dec 12, 2010

Copy link to clipboard

Copied

BKBK gave you a good suggestion about returning a query from that cfc.  Here are some other things to consider.

First, if the query in your getcategory function does not get used anywhere else except this page, it's a bad idea to have a cfc at all.  Your page will run faster if you simply put the query in your .cfm template.

Next, if the function is being used elsewhere, and you need an array to be returned, forget the bind syntax.  Simply call the function and loop through the array to populate your select.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 12, 2010 Dec 12, 2010

Copy link to clipboard

Copied

Problem is it is more than just the one drop down. I have a Category a Subcategory and a Subcategory2. I am using this code so when they choose a category it auto populates the subcategory field with only choises for that category and then it does the same for the subcategory2 from the subcategory selection. So I am using a CFC and binding the results from the previous drop down to it. I just don't understand why it is not actually putting the data intot he dropdowns like it should. Like I say code works fine on another site

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 12, 2010 Dec 12, 2010

Copy link to clipboard

Copied

Hi,

I hope this query is returning values and its not displaying in your drop downs.

We had the same problem in our jquery, the query is returning values, but its not showing up in the UI.

Then we found that, there were some extra spaces before, and after that the result was shown.(because we had used lots of css styles).

we just trim() function and it worked fine.

Use Firebug in Mozilla firefox for the debugging, its very useful.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 12, 2010 Dec 12, 2010

Copy link to clipboard

Copied

so, your CFC is in another directory??

I remember somebody told me that in the virtual directories this CFC wont work; but still I m not sure.

Please check it or some other members can clarify this one.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

Related selects were around long before the concept of binding form controls to cfcs.  Unless you are dealing with large amounts of data, it's probably more efficient to get all the data from the database once, and use javascript to control your selects.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

Hedge, an array wont work. Bind the cfselect to a query not to an array. Go back and modify the function to return a query instead.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

Here is a screenshot of it working (returning array).
screen1.gif


Now here is a screen shot of the exact same code on a different server not working.screen2.gif

the only difference between the two is the top one is using a cf mapping in the CF administrator for the cfc directory and the bottom one is not.

Iv'e tried the JavaScript path I have tried several other alternatives but this is reusuable code for a shopping cart for our sites so I want to use what is already working on the other site. All I did was copy and paste the code and not use a CF mapping. You can see though from the AJAX debugger that both sites are calling the CFC's so I wouldn't think the mapping would matter. The only problem I have is on the bottom one it is not putting the data fromt he CFC into the cfselect. I'm baffled. Same code

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied


the only difference between the two is the top one is using a cf mapping in the CF administrator for the cfc directory and the bottom one is not.

Put the cfm page containing the cfform in the directory named cfc. Then change the bind attribute to bind="cfc:GetCategory.getCategory()".

Alternatively, suppose the path of GetCategory.cfc from the web root is /dir1/dir2/cfc/GetCategory.cfc. Then use the bind attribute bind="cfc:dir1.dir2.cfc.GetCategory.getCategory()".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

Tried that. No luck

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

Ok for giggles I put a copy of the cfc on the other server (the one where the code was working) and I ran it just to see what would happen. It worked fine. So is there perhaps a setting someplace in CF administrator I am missing that should be checked that isn't or something? Makes no sense that it works on one server and not the other.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

Ok for giggles I put a copy of the cfc on the other server (the one  where the code was working) and I ran it just to see what would happen.  It worked fine. So is there perhaps a setting someplace in CF  administrator I am missing that should be checked that isn't or  something? Makes no sense that it works on one server and not the other.

We also had the problem, our CFC does not work on the different server.

we came to know that, CFC has some problem when we work in Virtual directories.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

Ok I found something else interesting. I don't know what it means but maybe somebody here does. Here is a screenshot from both sites.

The one that is NOT working.
Capture1.JPG

And from the one that is working.
Capture2.JPG
I noticed on the one that is working there is an additional checkbox at the bottom of the debugger screen for bind (I circled it in red) and on the site where the controls do not appear to be binding there is no such checkbox. I would think this leads weight to my idea that for whatever reason on the top screenshot the data is not being binded to the cfselect controls for some reason. The code is exactly the same. The databases are exactly the same. The only difference here is servers. Does this give any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

I glanced, but did not read thoroughly the thread to this point.

But have you confrimed that all necessary ColdFusion scripts are available to the User Client?

I.E. Does this, or something similar work and fetch a javascript file?  http://your.site.ext/CFIDE/scripts/wddx.js

I would wonder why you are getting some cfc functionality without access to these files, but I am no export on these features.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

Yep it pulls the JavaScript up fine. I have cfide set as a virtual directory so that shouldn't be an issue.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 13, 2010 Dec 13, 2010

Copy link to clipboard

Copied

You have a weird one here.

Can you use something like wireshark to see the exact data that is passing between the servers, not just what the browser is doing with them when it receives it.

Also, any chance of an extra Application.cfm|cfc hanging around monkeying with the JSON data (onRequestEnd.cfm may also play a role in this) by adding extra white space to the response.  I usually hear this as out and out breaking the JSON, but sugestions are getting scarce.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 14, 2010 Dec 14, 2010

Copy link to clipboard

Copied

The code is exactly the same. The databases are exactly the same. The only difference here is servers. Does this give any ideas?

Can you pls go into CFAdmin on each server and report back the exact CF version, as well as the patch level on both.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2010 Dec 14, 2010

Copy link to clipboard

Copied

Hedge-nfylYo wrote:

Ok I found something else interesting. I don't know what it means but maybe somebody here does. Here is a screenshot from both sites.

The one that is NOT working.
Capture1.JPG


I noticed on the one that is working there is an additional checkbox at the bottom of the debugger screen for bind (I circled it in red) and on the site where the controls do not appear to be binding there is no such checkbox. I would think this leads weight to my idea that for whatever reason on the top screenshot the data is not being binded to the cfselect controls for some reason. The code is exactly the same. The databases are exactly the same. The only difference here is servers. Does this give any ideas?

The data appears to be coming in, so this should work. Furthermore, I see that the data represents an array of dimension [2], which is equivalent to a two-column result set, hence equivalent to a query. That's yet another reason why it should work.

Take a look at the following modified version of the example I gave earlier. It might contain themes relevant to your case.

Employee.cfc

<cfcomponent output="false">
<cffunction name="getEmployee" access="remote" output="false" returntype="array">
<cfset var getAllEmployees = queryNew("","")>
<cfset var arr = arrayNew(2)>

<cfquery name = "getAllEmployees" dataSource = "cfdocexamples">
    SELECT Emp_ID,  FirstName || ' ' || LastName as Name
    FROM Employees
</cfquery>

<cfloop query="GetAllEmployees">
<cfset arr[currentrow][1]=emp_id>
<cfset arr[currentrow][2]=name>
</cfloop>

<cfreturn arr>

</cffunction>
</cfcomponent>

selectEmployee.cfm

<cfform>

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

</cfform>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 14, 2010 Dec 14, 2010

Copy link to clipboard

Copied

Ok I simplified it as much as I could. I made this the cfc

<cfcomponent output="false">
<cffunction name="getEmployee" access="remote" output="false" returntype="array">

<cfset var arr = arrayNew(2)>

<cfset arr[1][1] = 0>
<cfset arr[1][2] = '*SELECT ONE*'>
<cfset arr[2][1] = 1>
<cfset arr[2][2] = 'More Data'>

<cfreturn arr>

</cffunction>
</cfcomponent>

This worked and bound data to the cfselect.

So is it possible the data being returned is the problem? I don't see how it could be the problem in all 9 drop downs I am using it in though

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 14, 2010 Dec 14, 2010

Copy link to clipboard

Copied

Hedge wrote:

So is it possible the data being returned is the problem? I don't see how it could be the problem in all 9 drop downs I am using it in though

It could be a problem.  What is the data.

A quick example that occurs to me that would probably cause problems somewhere.

<cfset arr[1][1] = 0>
<cfset arr[1][2] = '*SELECT ONE*'>
<cfset arr[2][1] = 1>
<cfset arr[2][2] = '10 O'Clock'>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 14, 2010 Dec 14, 2010

Copy link to clipboard

Copied

Let's take the first drop down which is for just category for example. If I do a straight call to the cfc and method via URL like so.

http://mysite/admin/GetCategory.cfc?method=getCategory&category=9

I get the following reply. I broke them out to each line for readablility.

9.0Charts/Leaflets/Books

0*SELECT ONE*

3.0Accessories

9.0Charts/Leaflets/Books

19.0Clubs & Other Stitcher Specials

18.0Custom Mats

6.0Embellishments

4.0Fabric

12.0Fibers & Floss

14.0Frames

5.0Kits

17.0Learn How To...

10.0Limited Edition/Quantities

16.0Magazines/Publications

26.0Miniatures, Wool Applique, Embroidery & Other Techniques

15.0Miscellaneous

7.0Prefinished

23.0RETIRED MODEL Sale

22.0Rouge Chapeau Stitchers

21.0Russian Punch Needle

25.0Stitch For A Cause

24.0Stitches N Things Exclusive

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation