Solved

Using auto suggest get error "Error invoking CFC"

Posted on 2008-10-20
6
1,207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

 

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

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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