Trying to implement CFTHREAD...unsuccessfully :( - asynchronous

I previously made the post cfhttp in cfloop limit? use cfthread regarding making multiple CFHTTP requests to which I implemented the solution of making a XMLHttpRequest in a JS function to call my CFHTTP request from another file.
I've amended this so that it runs on an intertval timer but I seem to have an issue in that I'm only allowed by the host to make 3 requests per second but although I may set the interval time to even every 7 seconds I still end up timing out because the CFHTTP requests seem to pend and often make the request at the same time (which means it's taking me through the threshold).
I've read Ben Nadel's posts on using CFTHREAD but am having absolutely no joy implementing them at all.
My basic process at the moment is:-
Index.cfm contains a JS function that uses a XMLHttpRequest that calls playerSearch.cfm
playerSearch.cfm makes the CFHTTP request.
playerSearch.cfm then loops round the response and I display the current item from the loop as well as submitting another CFHTTP request to make a bid on the current item in the loop if it meets any of my IF conditions.
Index.cfm then keeps making requests every X amount of seconds.
Is there a way I can set the CFHTTP request itself to make its request every X amount of seconds (maybe using the sleep function in CFTHREAD?) and how would I display anything inside a CFTHREAD as I don't seem to be able to?
Also if I were able to make the CFHTTP request itself make the request every X amount of seconds then would I be better just calling that directly and would it keep looping continuously?
Any feedback would be much appreciated!
EDIT:
Index.cfm
<script>
var searchTimer = null,
searchInterval = 1000,
startPosition = 0;
function startSearch() {
if (searchTimer !== null) return;
searchTimer = setInterval(function () {
startPosition = startPosition + 16;
var xhr = new XMLHttpRequest();
xhr.open("GET", "playerSearch.cfm?startPosition="+startPosition, true);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
document.getElementById("counter").innerHTML = xhr.response;
} else {
// Error handling
}
}
};
xhr.onerror = function (e) {
// Error handling
};
xhr.send(null);
}, searchInterval);
}
function stopSearch() {
clearInterval(searchTimer);
searchTimer = null
}
</script>
playerSearch.cfm
<cfset Variables.startPosition = URL.startPosition />
<cfhttp url="https://utas.fut.ea.com/ut/game/fifa13/auctionhouse?type=player" method="post" result="getPlayer">
<cfhttpparam type="header" name="Accept" value="application/json" />
<cfhttpparam type="header" name="Accept-Language" value="en-GB" />
<cfhttpparam type="header" name="Connection" value="keep-alive" />
<cfhttpparam type="header" name="Content-Length" value="1" />
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="header" name="COOKIE" value="#Arguments.cookieString#">
<cfhttpparam type="header" name="Host" value="utas.fut.ea.com" />
<cfhttpparam type="header" name="Referer" value="http://cdn.easf.www.easports.com/soccer/static/flash/futFifaUltimateTeamPlugin/FifaUltimateTeam.swf" />
<cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" />
<cfhttpparam type="header" name="X-HTTP-Method-Override" value="GET" />
<cfhttpparam type="header" name="X-UT-Embed-Error" value="true" />
<cfhttpparam type="header" name="x-flash-version" value="11,7,700,224" />
<cfhttpparam type="header" name="X-UT-SID" value="#Arguments.sessionID#" />
</cfhttp>
<cfif getPlayer.StatusCode EQ "200 OK">
<!--- DESERIALIZE RETURNED JSON SO CAN LOOP ROUND EACH RESULT --->
<cfset Variables.searchResults = DeserializeJSON(getPlayer.FileContent) />
<!--- IF SEARCH RESULTS RETURNED --->
<cfset Variables.numResults = ArrayLen(Variables.searchResults.auctionInfo) />
<cfset Variables.bidsMade = 0 />
<table width="900" cellpadding="0" cellspacing="0">
<tr>
<th width="100" align="left" class="heading">Player Name</th>
<th width="70" align="left" class="heading">Rating</th>
<th width="50" align="left" class="heading">Formation</th>
<th width="80" align="left" class="heading">Position</th>
<th width="80" align="left" class="heading">Bid Status</th>
<th width="100" align="left" class="heading">Starting Price</th>
<th width="80" align="left" class="heading">BIN Price</th>
<th width="80" align="left" class="heading">Current Bid</th>
<th width="80" align="left" class="heading">My Bid</th>
<th width="120" align="left" class="heading">Ends</th>
</tr>
<cfloop from="1" to="#Variables.numResults#" index="i">
<cfscript>
// DEFAULT BID AMOUNT
Variables.bidAmount = 0;
// SET BID AMOUNT
// IF ITEM HAS BUY NOW PRICE AND IT IS LESS THAN QUICK SELL VALUE THEN BID THAT AMOUNT
if (Variables.searchResults.auctionInfo[i].buyNowPrice NEQ 0 AND Variables.searchResults.auctionInfo[i].buyNowPrice LT Variables.searchResults.auctionInfo[i].itemData.discardValue) {
Variables.bidAmount = Variables.searchResults.auctionInfo[i].buyNowPrice;
}
// ELSE IF QUICK SELL VALUE IS 228,231,235,238,242,245 OR 249 BID 200
else if (ListFind("228,231,235,238,242,245,249",Variables.searchResults.auctionInfo[i].itemData.discardValue) AND Variables.searchResults.auctionInfo[i].startingBid LTE 200 AND Variables.searchResults.auctionInfo[i].currentBid LT 200) {
Variables.bidAmount = 200;
}
// ELSE IF QUICK SELL VALUE IS 252,256,259 OR 300 BID 250
else if (ListFind("252,256,259,300",Variables.searchResults.auctionInfo[i].itemData.discardValue) AND Variables.searchResults.auctionInfo[i].startingBid LTE 250 AND Variables.searchResults.auctionInfo[i].currentBid LT 250) {
Variables.bidAmount = 250;
}
// GET MY CURRENT COIN TOTAL
Variables.getCoinTotal = Application.cfcs.Club.getCreditsTotal(SESSION.phishingKey,SESSION.sessionKey);
Variables.curCoinsData = DeserializeJSON(Variables.getCoinTotal.FileContent);
Variables.curCoins = Variables.curCoinsData.credits;
// IF I CURRENTLY HAVE ENOUGH COINS IN ACCOUNT PLACE BID
if (StructKeyExists(Variables,"curCoins") AND Variables.bidAmount NEQ 0 AND Variables.bidAmount LT Variables.curCoins) {
<cfset Variables.bidData = '{ "bid": ' & Variables.bidAmount & ' }'>
<cfset Variables.bidDataLength = Len(Variables.bidData) />
<cfhttp url="https://utas.fut.ea.com/ut/game/fifa13/trade/" & Variables.searchResults.auctionInfo[i].tradeID & "/bid" method="POST" result="makeBid">
<cfhttpparam type="header" name="Accept" value="application/json" />
<cfhttpparam type="header" name="Connection" value="keep-alive" />
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="header" name="Content-Length" value="#Variables.bidDataLength#" />
<cfhttpparam type="header" name="Host" value="utas.fut.ea.com" />
<cfhttpparam type="header" name="Referer" value="http://cdn.easf.www.easports.com/soccer/static/flash/futFifaUltimateTeamPlugin/FifaUltimateTeam.swf" />
<cfhttpparam type="header" name="X-HTTP-Method-Override" value="PUT" />
<cfhttpparam type="header" name="X-UT-SID" value="#SESSION.sessionKey#" />
<cfhttpparam type="header" name="COOKIE" value="#SESSION.phishingKey#">
<cfhttpparam type="header" name="User-Agent" value="Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36" />
<cfhttpparam type="body" value="#Variables.bidData#" />
</cfhttp>
Variables.bidsMade = Variables.bidsMade + 1;
} else {
Variables.bidAmount = 0;
}
</cfscript>
<cfoutput>
<tr>
<td align="left">#Variables.searchResults.auctionInfo[i].itemData.assetID#</td>
<td align="left">
#Variables.searchResults.auctionInfo[i].itemData.rating#
<cfif Variables.searchResults.auctionInfo[i].itemData.rareFlag EQ 0>
<cfelseif Variables.searchResults.auctionInfo[i].itemData.rareFlag EQ 1>
(Rare)
<cfelse>
(Something else)
</cfif>
</td>
<td align="left">#Variables.searchResults.auctionInfo[i].itemData.formation#</td>
<td align="left">#Variables.searchResults.auctionInfo[i].itemData.preferredPosition#</td>
<td align="left">#Variables.searchResults.auctionInfo[i].bidState#</td>
<td align="left">#Variables.searchResults.auctionInfo[i].startingBid#</td>
<td align="left">#Variables.searchResults.auctionInfo[i].buyNowPrice#</td>
<td align="left">#Variables.searchResults.auctionInfo[i].currentBid#</td>
<td align="left">#Variables.bidAmount#</td>
<td align="left">
<cfif Variables.searchResults.auctionInfo[i].tradeState EQ "active">
<cfset timeLeft = Variables.searchResults.auctionInfo[i].expires />
<cfset auctionEnds = DateAdd("s",timeLeft,Now()) />
#DateFormat(Variables.auctionEnds,"dd/mm/yyyy")# #TimeFormat(Variables.auctionEnds,"HH:mm:ss")#
<cfelse>
Ended
</cfif>
</td>
</tr>
</cfoutput>
</cfloop>
</table>
<br /><br />Bids Made: <cfoutput>#Variables.bidsMade#</cfoutput>
<cfelse><br />
The search returned an error.
<cfdump var="#getPlayer#">
</cfif>

Related

cfselect bind in cfc does not work when I enable Application.cfc

I am trying to create a form with 3 select boxes that are bound to a cfc (triple related cfselect). If I remove the Application.cfc, the code runs just fine, the select box gives me the data I need. However, when I add Application.cfc which has cflogin function which requires users to login before they are able to use any page than my triple related select boxes do not work anymore. The select box just doesn't give out any data from the query in the function. It still connects to the function page, because when I change the name on the bind of the cfselect, it will let me know that that function does not exist in the component. I am not sure what I have to do to make the triple related cfselect work with cflogin in place.
I am using ColdFusion 10
I really appreciate any suggestions.
Thanks, Niva
I added the code:
This is code on form
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Product Type:</td>
<td width="200">
<cfselect name="Selproducttype" bind="cfc:groupfnc.getproducttypeid()"
display="description" value="producttypeid" BindOnLoad="true"/></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Vendor:</td>
<td width="200">
<cfselect name="Selvendor" bind="cfc:groupfnc.getven({Selproducttype})"
display="fullname" value="vendorid" BindOnLoad="true"/></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Product:</td>
<td width="200">
<cfselect name="Selprod" bind="cfc:groupfnc.getprod({Selvendor})"
display="fullname" value="productid" BindOnLoad="true" /></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Sub Product:</td>
<td width="200">
<cfselect name="Selsubprod" bind="cfc:groupfnc.Getsub({Selprod})"
display="fullname" value="productsubid" /></td></tr>
Code on component: groupfnc.cfc
<cffunction name="getproducttypeid" access="remote" output="false" returntype="query">
<cfquery name="listproducttype" datasource="xxxxxx">
Select distinct producttypeid, (Case when producttypeid = '101' then 'Hotel'
when producttypeid='201' then 'optionalTour'
when producttypeid = '301' then 'Transporation'
when producttypeid = '501' then 'MISC'
when producttypeid = '601' then 'OTH' end) as description
From products
</cfquery>
<cfreturn listproducttype />
</cffunction>
<cffunction name="getven" access="remote" output="false" returntype="Query">
<cfargument name="Selproducttype" type="any" required="true">
<cfif ARGUMENTS.Selproducttype EQ "">
<cfset ARGUMENTS.Selproducttype = '0'>
</cfif>
<cfquery name="listven" datasource="xxxxxx">
SELECT distinct vendors.fullname, vendors.vendorid
from vendors, products
where products.vendorid= vendors.vendorid
and products.producttypeid = #ARGUMENTS.Selproducttype#
ORDER BY fullname
</cfquery>
<cfreturn listven />
</cffunction>
<cffunction name="getprod" access="remote" output="false" returntype="Query">
<cfargument name="Selvendor" type="any" required="true">
<cfif ARGUMENTS.Selvendor EQ "">
<cfset ARGUMENTS.Selvendor = '0'>
</cfif>
<cfquery name="Lstprod" datasource="xxxxxx">
Select productid, fullname from products
where vendorid = #ARGUMENTS.Selvendor#
order by fullname
</cfquery>
<!---</cfif>--->
<cfreturn Lstprod />
</cffunction>
<cffunction name="Getsub" access="remote" output="false" returntype="Query">
<cfargument name="Selprod" type="any" required="true">
<cfif ARGUMENTS.Selprod EQ "">
<cfset ARGUMENTS.Selprod = '0'>
</cfif>
<cfquery name="Lstsubprod" datasource="xxxxxx">
Select productsubid, fullname from productsubs
where productid = #ARGUMENTS.Selprod#
order by fullname
</cfquery>
<!---</cfif>--->
<cfreturn Lstsubprod />
</cffunction>
Here is my application.cfc
<cfcomponent>
<cfset This.name = "Orders">
<cfset This.Sessionmanagement="True">
<cfset This.loginstorage="session">
<cffunction name="OnRequestStart">
<cfargument name = "request" required="true"/>
<cfif IsDefined("Form.logout")>
<cflogout>
</cfif>
<cflogin>
<cfif NOT IsDefined("cflogin")>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfif cflogin.name IS "" OR cflogin.password IS "">
<cfoutput>
<h2>You must enter text in both the User Name and Password fields.
</h2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfquery name="loginQuery" dataSource="xxxxxx">
SELECT userid, roles
FROM logininfo
WHERE
userid = '#cflogin.name#'
AND upassword = '#cflogin.password#'
</cfquery>
<cfif loginQuery.roles NEQ "">
<cfloginuser name="#cflogin.name#" Password = "#cflogin.password#"
roles="#loginQuery.roles#">
<cfelse>
<cfoutput>
<H2>Your login information is not valid.<br>
Please Try again</H2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
</cfif>
</cfif>
</cfif>
</cflogin>
<cfif GetAuthUser() NEQ "">
<cfoutput>
<form action="securitytest.cfm" method="Post">
<input type="submit" Name="Logout" value="Logout">
</form>
</cfoutput>
</cfif>
</cffunction>
</cfcomponent>
I found the problem. Because in my Application.cfc has this part:
<form action="securitytest.cfm" method="Post">
<input type="submit" Name="Logout" value="Logout">
</form>
</cfoutput>
So looking at the ajax response the logout form is placed infornt so the select box didnt parse the value.I removed this partin the Application.cfc and the page run just fine.
Thank you so much for all your help!
^_^

CFSelect does not return the data from cfc

I want to bind this cfc to my cfselect:
This is my code for the cfc:
<cfcomponent output="false">
<cffunction name="getrates" returntype="query" output="false" access="remote">
<cfargument name="productno" required="yes" default="0" hint="Need productno.">
<cfset var getrate = "">
<cfquery name="getrate" datasource="xxxxxx">
select distinct ratecode, b.rateid as rateid
from productnos a , rates b
where a.productid = b.productid and a.productsubid = b.productsubid
and a.productno = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.productno#">
and (b.validto is null or b.validto > '2013-09-01')
</cfquery>
<cfreturn getrate>
</cffunction>
</cfcomponent>
and this is my code for test.cfm:
<CFPARAM name="FORM.productnumber" default="">
<cfif structKeyExists(form,'submit') >
<cfset productno = #FORM.productnumber#>
<table border="1" cellpadding="5" cellspacing="0" bordercolor="SeaGreen">
<tr>
<td colspan="2" bgcolor="DarkSeaGreen" style="color:Snow; font-size:large" align="center">
Choose Option For Tour
</td>
</tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold">
Select Option
</td>
<td >
<cfform name="selectrate" method="post" format="html">
<cfselect name="rateid" bind="cfc:pricelist.getrates({productno})" display="ratecode" value="rateid" bindonload="yes" />
</cfform>
</td>
</tr>
</table>
<br />
<CFELSE>
<CFOUTPUT>
<cfform action="testniva.cfm" method="POST">
<p>Please enter the product number<br />
<!--- include the most recent value of the submitted form, if you like, by simply setting the value to the variable --->
<cfinput type="text" name="productnumber"></p>
<p><cfinput type="submit" name="submit" value="Submit"></p>
<p><cfinput type="reset" Name="Reset" value="Cancel"> </p>
</cfform>
</CFOUTPUT>
</CFIF>
I cannot get the cfselect to bind because it said productno is undefined. Not sure what I need to do. If I replace bind="cfc:pricelist.getrates({productno}) to bind="cfc:pricelist.getrates(101) than it will bind, so I think somehow the productno didn't get carried over.

Coldfusion: Need to disable or block "Error invoking CFC - server error" error pop-up message

I have a .cfm and .cfc that I am using to edit data in a cfgrid on the .cfm, and it works, however 10% of the time I will get the following error message:
"Error invoking CFC /test/editCFgrid.cfc: Internal Server Error"
I tried using the debugging advice, however no luck.
Here is the CFM code:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<cfform name="artistform">
<cfgrid format="html" name="artistgrid" pagesize=11
striperows="yes"
bind="cfc:editCFgrid.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
delete="yes" insert="yes" selectmode="edit"
onchange="cfc:editCFgrid.saveArtist({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="firstname" header="First Name" />
<cfgridcolumn name="lastname" header="Last Name" />
<cfgridcolumn name="address" header="Address" />
<cfgridcolumn name="city" header="City" />
<cfgridcolumn name="state" header="State" />
<cfgridcolumn name="postalcode" header="Postal Code" />
<cfgridcolumn name="email" header="Email" />
<cfgridcolumn name="phone" header="Phone" />
<cfgridcolumn name="fax" header="Fax" />
<cfgridcolumn name="thepassword" header="Password" />
</cfgrid>
</cfform>
</body>
</html>
Here is the CFC code:
<cfcomponent output="FALSE">
<cffunction name="getArtists" hint="I extract artists from the database" access="remote" output="FALSE" returntype="struct">
<cfargument name="page" required="TRUE" hint="the page the grid is on" />
<cfargument name="pagesize" required="TRUE" hint="records displayed per page" />
<cfargument name="gridsortcolumn" required="TRUE" hint="selected column to sort" />
<cfargument name="gridsortdirection" required="TRUE" hint="the sort direction" />
<cfset var qArtists = "" />
<cfif arguments.gridsortcolumn eq "">
<cfset arguments.gridsortcolumn = "lastname" />
<cfset arguments.gridsortdirection = "asc" />
</cfif>
<cfquery name="qArtists" datasource="test_database">
SELECT *
FROM Artists
ORDER BY #arguments.gridsortcolumn# #arguments.gridsortdirection#
</cfquery>
<cfreturn QueryConvertForGrid( qArtists, arguments.page, arguments.pagesize ) />
</cffunction>
<cffunction name="saveArtist" type="any" hint="I insert, update or delete an artist" access="remote" output="FALSE" returntype="void">
<cfargument name="gridaction" type="any" required="TRUE" hint="I for insert, U for update and D for delete" />
<cfargument name="gridrow" type="any" required="TRUE" hint="the rows being inserted or updated" />
<cfargument name="gridchanged" type="any" hint="the changes" />
<cfset var qInsertArtist = "" />
<cfset var qUpdateArtist = "" />
<cfset var qDeleteArtist = "" />
<cfif IsStruct( arguments.gridrow ) and IsStruct( arguments.gridchanged )>
<cfif arguments.gridaction eq "I">
<cfquery name="qInsertArtist" datasource="test_database">
INSERT INTO Artists
(firstname, lastname, address, city, state, postalcode, email, phone, fax, thepassword)
VALUES
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.firstname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.lastname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.address#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.city#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.state#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.postalcode#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.email#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.phone#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.fax#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.thepassword#" />)
</cfquery>
<cfelseif arguments.gridaction eq "U">
<cfset var colname = StructKeyList( arguments.gridchanged ) />
<cfset var value = StructFind( arguments.gridchanged, colname ) />
<cfquery name="qUpdateArtist" datasource="test_database">
UPDATE Artists
SET #colname# = <cfqueryparam value="#value#" />
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
<cfelseif arguments.gridaction eq "D">
<cfquery name="qDeleteArtist" datasource="test_database">
DELETE FROM Artists
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
</cfif>
</cfif>
</cffunction>
</cfcomponent>
Each function (edit, insert, delete, etc) works, but it randomly will generate the error. Ultimately, I am seeking a code that will ignore/block/"OK" the error message so the user won't see it.
Any help will be greatly appreciated! I have spent the entire day (9 hours) googling for an answer, but I haven't found any. I do not have access to the CF Admin Log, I'm just a regular developer. Thanks!
Google chrome, firebug in firefox, IE developer tools can all help you with this.
In google chrome (my preference), right click on your page > inspect element. Then go to the network tab. You'll have to refresh your web page. Then you will see your cfc in the list of files (probably RED). Right click > open in new tab, and you'll open the cfc directly with all the arguments being called. You should then be able to see your error.
There is no ignore/block/ok. You need to fix the error.
Perhaps a time out or a SQL error. To get the full error use: cferror, this tag show a full debug information (better than debug server info) I sent it to me by mail:
Put this on you Application file:
<cferror type="exception" template="error.cfm" />
<cferror type="request" template="error.cfm" />
Create a "error.cfm" file with:
"Error message"
<cfsavecontent variable="errorContent">
<cfoutput>
An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />
<h2>Error:</h2>
<cfdump var="#error#" label="Error">
<h2>Form:</h2>
<cfdump var="#form#" label="Form">
<h2>URL:</h2>
<cfdump var="#url#" label="URL">
<h2>SESSION:</h2>
<cfdump var="#SESSION#" label="SESSION">
</cfoutput>
</cfsavecontent>
<cfmail to="mail#mymail.com" from="mail#mymail.com" subject="Error on #cgi.server_name#: #error.message#" type="html">
#errorContent#
</cfmail>
There is a way to ignore/block/ok the "error" message with the following script:
<script>ColdFusion.setGlobalErrorHandler(function (error)
{mygrid = ColdFusion.Grid.refresh ('artistgrid', false);
}
);
</script>
Insert this script in the CFM files, and you're good to go! Being that the error that I was encountering was not impacting the function (editing the cells) of the cfgrid (the pop-up message was being more of a nuisance then anything else). Hopefully this solution will help others!
You do not need to use the 'Grid.refresh' command in the script, you can use anything command you want.
Thanks everyone who attempted to answer my issue!

Weird behaviour with Chrome browser and data bound button

I've noticed some strange browser specific weirdness with Google
Chrome with some data bound buttons, in that when you navigate away
from the page then use the browsers back button the data bind displays
different data. If you then hit refresh it resets to the correct data.
It doesn't happen in Firefox or Explorer 7.
I had actually entered the data bound bool button example to CF
Cookbook http://cookbooks.adobe.com/post_Using_cfinput_buttons_and_data_binding_to_toggle_d-16390.html so the files I'm using are there, direct link is http://cookbooks.adobe.com/index.cfm?event=getFile&fileId=6902
but now I have spotted this cross browser quirk I feel I should take
it down unless of course you can help me figure out what is going
on!
Any clues appreciated.
bool_buttons.cfm
<cfset url.messageID=28>
<CFSET application.dsn = "data">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<cfform>
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle1#click},'referral', 'Referral', 'Message')" name="toggle1" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle2#click},'viewed', 'Read', 'Unread')" name="toggle2" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle3#click},'actioned', 'Actioned', 'Pending')" name="toggle3" value="" bindonload="YES">
</cfform>
</body>
</html>
messageProcess.cfc
<cfcomponent>
<cffunction access="remote" name="togglebool" output="true" returntype="any" displayname="Toggle boolean value in message record" hint="Toggles boolean value in message record">
<cfargument required="true" name="dsn" type="string"/>
<cfargument required="true" name="messageID" type="numeric"/>
<cfargument required="true" name="buttonLabel" type="string"/>
<cfargument required="true" name="switchName" type="string"/>
<cfargument required="true" name="switchOnLabel" type="string"/>
<cfargument required="true" name="switchOffLabel" type="string"/>
<cfset var returnMessage = "" />
<cfset var temp = "" />
<cfquery datasource='#arguments.dsn#' name="getSwitchData">
SELECT #arguments.switchName#
FROM messages
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfset temp="getswitchdata."&#switchName#>
<cfif #Evaluate(temp)# is 1>
<cfset returnMessage="#arguments.switchOnLabel#">
<cfelse>
<cfset returnMessage="#arguments.switchOffLabel#">
</cfif>
<cfif buttonLabel eq "">
<cfreturn returnMessage>
<cfelseif buttonLabel eq "#arguments.switchOffLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=1
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOnLabel#">
<cfelseif buttonLabel eq "#arguments.switchOnLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=0
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOffLabel#">
</cfif>
</cffunction>
</cfcomponent>
This is a Google Chrome bug, I had a similar case and opened a ticket here

How can I bind a button control to a cfc to toggle a boolean database value

I would like to able to bind a series of 3 buttons to toggle 3 boolean values on a database message entry. The boolean database entries are read|unread, actioned|pending, referral|message and the message entry has the unique key "messageID". I want the buttons to display the record starting values (which I presume is bindonload="true").
I've limped towards
<cfform>
<cfinput type="hidden" name="switchName" value="read">
<cfinput type="button" bind="cfc:cfcs.messages.toggle({toggle#click},{switchName#none})" name="toggleRead" value="Read" bindonload="true">
</cfform>
and in the cfc
<cffunction access="remote" name="toggle" output="false" returntype="any" >
<cfargument required="true" name="toggle" type="any"/>
<cfargument required="true" name="switchName" type="any"/>
<cfif toggle eq "Read">
<cfreturn "Unread">
<cfelseif toggle eq "Unread">
<cfreturn "Read">
</cfif>
</cffunction>
This gets me some of the way there, in so far as it toggles the button label, but I'm foxed on how to pick up the initial db values to display the initial status.
Also is there a way to pass other variables in the bind statement without using hidden fields and control#none format, e.g. I will need to pass in the messageID so I can update the correct record. I wouldn't have put in the switchName input if I knew how to simply pass the switchName variable in a beter way.
Many thanks for any light you can shed?
How about...
<cfinput type="button" bind="cfc:cfcs.messages.toggle({toggle#click}, #switchName#)" value="#initialValue#" bindonload="false">
or alternatively:
<cfajaxproxy bind="javascript:yourJSFunc({toggle#click})">
and in your yourJSFunc, use whatever JS var's you need.
That helped Henry.
I got it working, though it feels a bit kludgy...
<cfform>
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle1#click},'referral', 'Referral', 'Message')" name="toggle1" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle2#click},'viewed', 'Read', 'Unread')" name="toggle2" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle3#click},'actioned', 'Actioned', 'Pending')" name="toggle3" value="" bindonload="YES">
</cfform>
and the cfc
<cfcomponent>
<cffunction access="remote" name="togglebool" output="true" returntype="any" displayname="Toggle boolean value in message record" hint="Toggles boolean value in message record">
<cfargument required="true" name="dsn" type="string"/>
<cfargument required="true" name="messageID" type="numeric"/>
<cfargument required="true" name="buttonLabel" type="string"/>
<cfargument required="true" name="switchName" type="string"/>
<cfargument required="true" name="switchOnLabel" type="string"/>
<cfargument required="true" name="switchOffLabel" type="string"/>
<cfset var returnMessage = "" />
<cfset var temp = "" />
<cfquery datasource='#arguments.dsn#' name="getSwitchData">
SELECT #arguments.switchName#
FROM messages
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfset temp="getswitchdata."&#switchName#>
<cfif #Evaluate(temp)# is 1>
<cfset returnMessage="#arguments.switchOnLabel#">
<cfelse>
<cfset returnMessage="#arguments.switchOffLabel#">
</cfif>
<cfif buttonLabel eq "">
<cfreturn returnMessage>
<cfelseif buttonLabel eq "#arguments.switchOffLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=1
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOnLabel#">
<cfelseif buttonLabel eq "#arguments.switchOnLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=0
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOffLabel#">
</cfif>
</cffunction>
If there's a slicker way please let me know.

Resources