Skip to main content
Inspiring
May 3, 2012
Answered

error handling inside cfc

  • May 3, 2012
  • 1 reply
  • 4644 views

i have a cfgrid bound to a text field as well as a cfc

text field passes a value to cfc where it's being used as a parameter for a query . query can return zero records, when that happens, browser throws a json error

how can i trap this error inside the cfc and return a message to user? (without using a proxy)

thanks

This topic has been closed for replies.
Correct answer ion

there isn't any calling code, it's just a cfgrid bound to the cfc.

Ah, sorry: I came into this late and didn't read the earlier posts.

<cfgrid> has an onerror handler for when - I presume - a bind operation fails.  Does this not give you what you want?  The JS function can do anything, after all.

Reading here:

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a01.html#WSc3ff6d0ea77859461172e0811cbec22c24-72e0

That said, I dunno how to send the message back from the server, but in this case perhaps you don't: you're just trying to pass back a hard-coded string if you get an error, so why not simply hard-code the message in the <cfgrid> code?

I've never used this functionality before, so I'm pretty vague on how it works... if it sounds like it'll work, then perhaps google about a bit.  Or maybe someone else here is au fait with how it all comes together..?

--

Adam


well, some people would say it's crazy to work a full day on throwing an alert, and i tend to agree. Thanks everybody for suggestions, for what it's worth, this is how it works:

do NOT specify the onLoad event in cfgrid, do NOT use ajaxonload.

instead, create this js function, with THIS particular syntax:

getTotalApps = function() {

var isGrid = ColdFusion.Grid.getGridObject('myGrid');

var isData = isGrid.getStore();

isData.addListener("load",function() {

    if(isData.totalLength == 0)

        {

          alert("No records found");

          return false;

        }

    });

}

ColdFusion.Event.registerOnLoad(getTotalApps,null,false,true);

1 reply

Inspiring
May 3, 2012

sounds like if/else 101 to me.  What would you like to happen if 0 records are applied.

ionAuthor
Inspiring
May 4, 2012

Thanks for answering,

i've tried the obvious <cfif myQuery.recordCount eq 0> No records found<cfabort><cfif>

however, looks like inside a cfc <cfabort> simply doesn't work, the cfc is trying to return the structure to the calling cfm anyway and the structure is empty, hence the json error

i've also tried (with same result)

  <cfif myQuery.recordCount eq 0>

    <script language="JavaScript">

       alert("No records found");

    </script>

  </cfif>

ionAuthor
Inspiring
May 4, 2012

i found the reason, the text field the grid is bound to is taking its values from an Oracle database, which is case sensitive. my query was matching the search param on lower(myColumn) on the WHERE clause, but didn't bother to do the same on the SELECT lower(myColumn). as a result, the value of the text field could have both upper and lower case chars, while the query could have only lower.

soon as i changed the qry to select lower(myColumn) where lower(myValue) the error went away

thanks