Solved

Using auto suggest get error "Error invoking CFC"

Posted on 2008-10-20
6
1,196 Views
Last Modified: 2013-12-24
Trying the following Ben Forta example(http://www.forta.com/blog/index.cfm/2007/5/31/ColdFusion-Ajax-Tutorial-1-AutoSuggest ) is successful,

<!--- Get data --->
<cfquery datasource="cfartgallery" name="data">
SELECT artname
FROM art
ORDER BY artname
</cfquery>

<!--- The form --->
<cfform>
Art:
<!--- Populate auto-suggest control --->
<cfinput type="text"
      name="artname"
      autosuggest="#ValueList(data.artname)#">
</cfform>

When I try to use the CFC example I get an "Error invoking CFC" message,

<cfcomponent
output="false">

<cfset THIS.dsn="cfartgallery">

<!--- Lookup used for auto suggest --->
<cffunction name="lookupArt" access="remote" returntype="string">
          <cfargument name="search" type="any" required="false" default="">

          <!--- Define variables --->
          <cfset var data="">

          <!--- Do search --->
          <cfquery datasource="#THIS.dsn#" name="data">
          SELECT artname
          FROM art
          WHERE UCase(artname) LIKE Ucase('#ARGUMENTS.search#%')
          ORDER BY artname
          </cfquery>

          <!--- And return it --->
          <cfreturn ValueList(data.artname)>
</cffunction>
   
</cfcomponent>
-----------------------------------------------------------
<cfform>
Art:
<cfinput type="text"
      name="artname"
      autosuggest="cfc:art.lookupArt({cfautosuggestvalue})">
</cfform>


Other queries work in this directory.
0
Comment
Question by:talahi
6 Comments
 
LVL 27

Expert Comment

by:azadisaryev
ID: 22761628
iirc, a function with access="remote" cannot have optional arguments. try changing your cfargument to required="true"

as with all cf ajax features, you can add ?cfdebug to the url of your page to enable cf ajax debugger (provided it is enabled in cf admin), and see somewhat more detailed error messages.

and using firefox with firebug can help you even more.
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 22761644
make sure you point to the right path where your cfc are stored

0
 
LVL 39

Expert Comment

by:gdemaria
ID: 22766962
Your CFC should be called art.cfc and be located in the root directory.  Is that the case?  When binding, it will not find it in other locations.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:talahi
ID: 22767585
Thanks for the responses. Here is the error I receive,

" Error invoking CFC /art.cfc : Element DS is undefined in VARIABLES. [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]"

I don't believe this "Element DS is undefined in VARIABLES" since it is used in the first attempt and works fine, even when hardcoded as defined in the application.cfm file.

<cfquery datasource="#variables.ds#" name="data">
SELECT artname
FROM art
ORDER BY artname
</cfquery>

- I changed cfargument to required="true" but that didn't affect the result.

-  root directory.  Right now the art.cfc is in the same location as the cfform page calling it.  My CF book also mentions putting it in the '...\components folder but that didn't work (not sure how to change the path in the CFFORM calling it.

I also see information about using <cfinvoke intead.  Looking at that now.

Here is what I see when I look at the View Source page in Firefox.  It looks like all the ajax support files are being found.

<!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><script type="text/javascript">_cf_loadingtexthtml="<div align='center'><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/>";
_cf_contextpath="";
_cf_ajaxscriptsrc="/CFIDE/scripts/ajax";
_cf_jsonprefix='//';
</script><script type="text/javascript" src="/CFIDE/scripts/ajax/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/yui/animation/animation-min.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/yui/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/messages/cfmessage.js"></script>

<script type="text/javascript" src="/CFIDE/scripts/ajax/package/cfajax.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/package/cfautosuggest.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="/CFIDE/scripts/ajax/resources/yui/yui.css" />
<link rel="stylesheet" type="text/css" href="/CFIDE/scripts/ajax/resources/cf/cf.css" />

<script type="text/javascript">
      ColdFusion.Ajax.importTag('CFINPUT-AUTOSUGGEST');
</script>

      <script type="text/javascript">
            var _cf_autosuggest_init_1224599433739=function()
            {
                  var _cf_autosuggestarray=[];
                  
                  var _cf_autosuggestdatasource= new YAHOO.widget.DS_JSArray( _cf_autosuggestarray);
                  var _cf_autosuggest= new YAHOO.widget.AutoComplete( 'artname','artnamecontainer',_cf_autosuggestdatasource);
                  _cf_autosuggest.onbinderror=null;
                  _cf_autosuggest.prehighlightClassName = "yui-ac-prehighlight";
                  _cf_autosuggest.typeAhead = false;
                  _cf_autosuggest.maxResultsDisplayed = 10;
                  _cf_autosuggest.useShadow = true;
                  _cf_autosuggest.showloadingicon = true;
                  _cf_autosuggest.containerCollapseEvent.subscribe(ColdFusion.Autosuggest.triggerOnChange);
                  _cf_autosuggest.id='artname'
                  _cf_autosuggest.valuePresent=false
                  _cf_autosuggest.doBeforeExpandContainer=_cf_resetLoadingIcon_1224599433740;
                  
                  YAHOO.util.Event.addListener("artname","blur",_cf_resetLoadingIcon_1224599433740);
                  ColdFusion.objectCache["artname"] = _cf_autosuggest;
                  document.getElementById("artnamecontainer").style.left = document.getElementById("artname").offsetLeft;
                  YAHOO.util.Event.addListener("artname","keyup",_cf_onKeyUp_1224599433741,_cf_autosuggest);
            };ColdFusion.Event.registerOnLoad(_cf_autosuggest_init_1224599433739);
            _cf_resetLoadingIcon_1224599433740=function()
            {
                  document.getElementById("artname_cf_button").src='/CFIDE/scripts/ajax/resources/cf/images/static.gif';
                  return true;
            };_cf_onKeyUp_1224599433741=function( arg,autosuggest)
            {
                  
                  var cfautosuggestvalue=document.getElementById('artname').value;
                  
                  if( ColdFusion.Autosuggest.checkToMakeBindCall(arg, "artname", autosuggest, cfautosuggestvalue) ){
                  ColdFusion.Bind.cfcBindHandler(null, {'bindTo':ColdFusion.Autosuggest.loadAutoSuggest,'bindToAttr':'true','cfc':'/art.cfc','cfcFunction':'lookupArt','bindExpr':[['search',cfautosuggestvalue]], 'bindToParams': { 'autosuggestid':"artname" }});
                        }
            };
            
      </script>
      <script type="text/javascript">
<!--
    _CF_checkCFForm_1 = function(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;


        //display error messages and return success
        if( _CF_error_exists )
        {
            if( _CF_error_messages.length > 0 )
            {
                // show alert() message
                _CF_onErrorAlert(_CF_error_messages);
                // set focus to first form error, if the field supports js focus().
                if( _CF_this[_CF_FirstErrorField].type == "text" )
                { _CF_this[_CF_FirstErrorField].focus(); }

            }
            return false;
        }else {
            return true;
        }
    }
//-->
</script>
</head>

<body>

<form name="CFForm_1" id="CFForm_1" action="/test_autosuggest.cfm" method="post" onsubmit="return _CF_checkCFForm_1(this)">
artname:

<div  id="artnameautosuggest" class="autosuggest">
      <div  style="float:left;">
            <input name="artname" id="artname"  type="text" class="autosuggestinput"  />

       </div><div  id="artnameloadingicon" style="float:left;">
            
            <img id='artname_cf_button' src="/CFIDE/scripts/ajax/resources/cf/images/static.gif"/>
       </div><div  id="artnamecontainer" class="autosuggestcontainer" style="float:left;">
            
       </div>
 </div>  
</form>
 

</body>
</html>
0
 

Author Comment

by:talahi
ID: 22767875
It seems to work now but not sure why.  Still looking at it.
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 200 total points
ID: 22768050
You are binding a variable, so I don't think cfinvoke or createObject apply here.  Those are for using a cfc, which is different.

> My CF book also mentions putting it in the '...\components folder but that didn't work

Binding is different than invoking.  The location of the cfc is more specific (perhaps because of a bug, who knows).  I think it needs to be in your root or a direct descendant of it.  It's worth testing.  I had a lot of trouble with this as I could not put it in my library with other CFC files.

>  I don't believe this "Element DS is undefined in VARIABLES"

Keep in mind that the variables scope is not a global scope.  If you are defining it in the application.cfm file it is NOT guaranteed to transcend all your files.   The "request" scope is global.  You can also use application scope for this as its a static value and likely applies to all users.

0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question