Solved

Using auto suggest get error "Error invoking CFC"

Posted on 2008-10-20
6
1,174 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
Comment Utility
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
Comment Utility
make sure you point to the right path where your cfc are stored

0
 
LVL 39

Expert Comment

by:gdemaria
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:talahi
Comment Utility
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
Comment Utility
It seems to work now but not sure why.  Still looking at it.
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 200 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now