Solved

Using auto suggest get error "Error invoking CFC"

Posted on 2008-10-20
6
1,221 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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