Copy link to clipboard
Copied
Googled this for several hours, hope I'm missing the obvious as usual...
I'm using CF9 and IIS7. Followed/tailored simple autosuggest code from Ben Forta.
Came up with HTML:
<cfinput type="text" name="Employer" size="50" autosuggest="cfc:employer.lookupEmployer({cfautosuggestvalue})">
and a CFC named employer.cfc in the current template folder:
<cfcomponent output="false">
<cffunction name="lookupEmployer" access="remote" returntype="array">
<cfargument name="search" type="any" required="false" default="">
<cfset var data="">
<cfset var result=ArrayNew(1)>
<cfquery name="data" datasource="Binkley">
Select lname
From tdLicense
Order By lname
</cfquery>
<cfloop query="data">
<cfset ArrayAppend(result, lname)>
</cfloop>
<cfreturn result>
</cffunction>
</cfcomponent>
The query runs fine in a test cfm file.
Any help appreciated.
Copy link to clipboard
Copied
What URL is JS hitting when making the request to employer.cfc? And is employer.cfc at that URL?
--
Adam
Copy link to clipboard
Copied
employer.cfc is in the same folder as the cfm template it is called from. I don't know what you mean by "What URL is JS hitting".
I'm pretty new at this tgype of feathre as we just upgraded from CF5 to CF 9...
Copy link to clipboard
Copied
When you use that autosuggest stuff, it writes some Javascript out on the client which calls your CFC remotely when the (I'm guessing) onkeyup event fires on the browser. So onkeyup (or whichever event it actually is if not that) Javascript will be making an AJAX request back to your server to get what to suggest. Make sense? What is the URL it is requesting?
--
Adam
Copy link to clipboard
Copied
Adam, I understand how Ajax works... But I have no idea how what url coldfusion uses for the request back????
Like I said, the cfm template and the cfc are inj the same folder. The template is named comboreceipt.cfm, the cfc is named employer.cfc.
Copy link to clipboard
Copied
Adam, I understand how Ajax works... But I have no idea how what url coldfusion uses for the request back????
They same way you'd find out the URL of any AJAX (or otherwise) request being made from the browser: use Firebug - or something - to look at the requests being made.
Like I said, the cfm template and the cfc are inj the same folder.
This does not matter. The CFM is not talking to the CFC; the browser is talking to the CFC. The browser is talking to the CFC via a URL.
You have this code:
<cfinput type="text" name="Employer" size="50" autosuggest="cfc:employer.lookupEmployer({cfautosuggestvalue})">
All that autosuggest bumpf is doing is telling CF to generate some Javascript - which then gets sent to the browser to be executed when appropriate - to make an AJAX request back to the CF server for it to get some data which it then sends back to the browser to be put in the input box. There is no connection between the CFM code and the CFC code at all. The CFM generates mark-up and JS and sends it to the browser. The browser then executes it, and part of the execution might be call back to the CF server - to the CFC - to provide some data for the input box.
Can you please go to my blog and read this article:
http://adamcameroncoldfusion.blogspot.co.uk/2012/10/the-coldfusion-requestresponse-process.html
That is specific to "normal" requests, but the same applies to AJAX. You say you understand this, but I'm not so sure.
--
Adam
Copy link to clipboard
Copied
I was just hoping to use the cfform built in version for some simple auto suggest needs. Obviously it does not work in CF 9.0.0
I'll just code it from scratch.
Thank you anyway.
Copy link to clipboard
Copied
I was just hoping to use the cfform built in version for some simple auto suggest needs. Obviously it does not work in CF 9.0.0
"you not being able to get it to work" does not equate to "it not working".
You need to know how your tools work and what to do with them before you can hope to use them correctly. I don't think that's too much to expect, is it?
--
Adam
Copy link to clipboard
Copied
Actually, given the simplicity of the test code I attempted to use, it absolutely should work.
Copy link to clipboard
Copied
LyndonPatton wrote:
Actually, given the simplicity of the test code I attempted to use, it absolutely should work.
Absolutely. The whole purpose of the exercise is to look up a collection, based on a given search filter. Your query fails to do any filtering at the moment. Modify it to something like
Select distinct lname
From tdLicense
Where lname like <cfqueryparam value="#arguments.search#%" cfsqltype="cf_sql_varchar">
Order By lname
Copy link to clipboard
Copied
Strictly for troubleshooting, try creating an object from the cfc.
Copy link to clipboard
Copied
Oh boy, I lookd at a few examples but don't see how to create an object from a cfc in this context.
Copy link to clipboard
Copied
Dan just wants to check that the CFC actually compiles (well that's my guess). So just write some code that creates an instance of the CFC, eg:
myObj = new employer();
The next step would be to call the lookupEmployer() method remotely yourself, to see if that works, eg:
http://yourdomain/path/to/employer.cfc?method=lookupEmployer&search=some%20search%20string
Does that return expected results?
--
Adam
Copy link to clipboard
Copied
" myObj = new employer();"
Is this cfscript? js? a cf tag????
I'm very new, I'm not trying to be a bother but I'm lost here.
Copy link to clipboard
Copied
" myObj = new employer();"
Is this cfscript? js? a cf tag????
I'm very new, I'm not trying to be a bother but I'm lost here.
It's a CFML statement. The new operator is new to CF9; you could instead to this:
myObj = createObject("employer")
Or use <cfobject> or <cfinvoke> or whatever.
If you're fresh from CF5, you've got a bunch of reading to do, because CFML has moved an awful lot since 2001.
Firstly read these two (all the subpages, I mean):
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec1a60c-7ffa.html
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec17576-7fef.html
Then this:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7fec.html (all of it)
Then this:
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a27.html (again, all of it)
Then try to write code using this stuff.
It's a lot of work, but you've let a lot of water run under the bridge between upgrades. CFML is a very very different beast in CF9 than it was in CF5. And the way one writes code is (or at least should be) almost completely different.
--
Adam
Copy link to clipboard
Copied
The next step would be to call the lookupEmployer() method remotely yourself, to see if that works, eg:
http://yourdomain/path/to/employer.cfc?method=lookupEmployer&search=some%20search%20string
Does that return expected results?
Did you ever do this?
--
Adam
Copy link to clipboard
Copied
I have never done this before so I gave it a shot. I was able to get your error message when I did something stupid in my cfc which caused it to not compile. The error message is misleading.
Now I'm going to follow my earlier advice of creating the object separately. Then I'll run my method from that object to make sure it works properly before trying the autosuggest. I suggest you do the same.
Copy link to clipboard
Copied
Thank you for looking into it.
I'd goggled the issue for several hours before posting this; There are postings going back to 2007 with the same issue, very few folks ever got a solution. It seems those that did find a fix were running a web server other than IIS. A clue maybe?
The only difference in my cfc and the one posted in the Ben Forts tutorial blog is the <cfquery> and I kept mine very simple. Mr. Forta responded to the exact same error, in the comments section of the blog post the example/tutorial was published in, for several years and it seems it was never resolved for most users. http://www.forta.com/blog/index.cfm/2007/5/31/coldfusion-ajax-tutorial-1-autosuggest
I'll have to read the training links you provided before I can follow you in using the "object" method. A little over my head. I work for a small state agency and because of funding issues I was stuck with CF5 for a decade. That led to me having to learn javascript and use that to keep the UI up to a level expected by my users. That left me way behind the rest of the CF community when it comes to issues like this. I wrote an Ajax/JSON solution for this requirement since my last post and it works fine, been doing that for years... I was just hoping to occasionally use the built-in cfform autosuggest when the requirement is simple. It seems I just don't have the skills to follow the suggestions you guys have been providing in this thread.
I hope I didn't come off as short tempered, I think I was a little overwhelmed by the feedback I was getting... I really do appreciate the help.
Copy link to clipboard
Copied
The only difference in my cfc and the one posted in the Ben Forts tutorial blog is the <cfquery> and I kept mine very simple. Mr. Forta responded to the exact same error, in the comments section of the blog post the example/tutorial was published in, for several years and it seems it was never resolved for most users. http://www.forta.com/blog/index.cfm/2007/5/31/coldfusion-ajax-tutorial -1-autosuggest
Not that it's much help, but I copy and pasted Ben's example code - modifying it only to fake the DB call as I don't have that datasource - and it worked fine other than that. I have not modified my environment in any way to facilitate it working: this is a very bog-standard CF 9.0.1 install.
This is not much help to you, but short of you providing the info I asked, I dunno how we are able to help you further with this.
--
Adam
Copy link to clipboard
Copied
Oh, and just another idea, in addition to the one I gave earlier, this time more relevant to the question. To rule out any runtime bugs, rename the CFC to employers.cfc and modify the autosuggest attribute to autosuggest="cfc:employers.lookupEmployer({cfautosuggestvalue})". Any joy?
Copy link to clipboard
Copied
I did the rename suggestion and same error:
The specified CFC Employer could not be found.
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings
The specified CFC Employer could not be found. | |
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings. | |
The error occurred in C:\Workgroups\WebPages\binkley\TrackData\NoMenu\test.cfm: line 2 | |
1 : <cfform name="emp" method="get" > |
I changed the name and id of the input element to something other than the cfc name (grasping at straws)
I’m still trying to figure out how to create the object… Our point of sale app has to be changed before Dec 1 (was going to use this autosuggest in that effort) and will begin digging in to this when I finish the POS changes…
Thanks!
Copy link to clipboard
Copied
LyndonPatton wrote:
I did the rename suggestion and same error:
The specified CFC Employer could not be found.
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings
The specified CFC Employer could not be found.
The path to the CFC must be specified as a full path, or as a relative path from the current template, without the use of mappings. The error occurred in C:\Workgroups\WebPages\binkley\TrackData\NoMenu\test.cfm: line 2 1 : <cfform name="emp" method="get" >
2 : <cfinput type="text" name="Employerx" id="Employerx" size="50" autosuggest="cfc:employer.lookupEmployer({cfautosuggestvalue})">
3 : </cfform>I changed the name and id of the input element to something other than the cfc name (grasping at straws)
You have misunderstood me. I suggested you change the name of the CFC file from employer.cfc to employers.cfc. Following the code example you've just given, I am suggesting you rename the file
C:\Workgroups\WebPages\binkley\TrackData\NoMenu\employer.cfc
to
C:\Workgroups\WebPages\binkley\TrackData\NoMenu\employers.cfc
Then modify the cfinput tag accordingly:
<cfinput type="text" name="Employer" size="50" autosuggest="cfc:employers.lookupEmployer({cfautosuggestvalue})">
In fact, another suggestion is, before trying anything else, run the following code on a CFM page:
<cfoutput>#fileExists("C:\Workgroups\WebPages\binkley\TrackData\NoMenu\employer.cfc")#</cfoutput>
If the answer is No, then that will explain why you get the error.
Copy link to clipboard
Copied
I did miss the "s"...
Renamed the cfc file and the cfc call to cfc:employers.lookupEmployer({cfautosuggestvalue})
same result.
Ran the thefileExists function, it returned YES
Additionally, I set maxrows="25" in the cfquery tag thinking maybe timeout???
Same error.
Copy link to clipboard
Copied
It looks like your directory structure confuses Coldfusion. What is the absolute path of your root directory?
Copy link to clipboard
Copied
The physical path for the virtual directory in IIS is C:\Workgroups\WebPages\binkley
Is that what you mean?
Or is it