Ask a Jedi: Ajax-bound requests and onRequest
So this is definitely something I've covered more than once, but as the questions keep coming in, I'm going to keep blogging it. My real hope is that Adobe listens in here as I think this is something that really needs changing in ColdFusion. Anyway, the question, from Samer:
I found a wired case, if you use onRequest function in Application.cfc and use cfgrid with bind attribute, it always return empty query to the grid "Response is Empty" !!
Can you help?
This is a fairly simple problem. onRequest, if it exists, breaks all flash remoting and CFC calls (remote calls I mean). Make sure you understand that. It doesn't matter what you do in onRequest - the mere existence of the method will call Flash Remoting/CFC (Remote) operations fail. Period.
As I said, this is something I truly wish Adobe would just fix as all it does is trip people up.
There is a way around it. Sean Corfield has a nice little work around that involves adding the following code to your onRequestStart (not onRequest, but onRequestStart):
<cfif listlast(arguments.thePage,".") is "cfc">
<cfset StructDelete(this, "onRequest") />
<cfset StructDelete(variables,"onRequest")/>
</cfif>
Comments
Is Adobe all consumed with Flex and Air now?
Thks.
Don
code,
<cfscript>
daysForData = 3;
</cfscript>
in the application.cfm framework
to its equivalent in the application.cfc framework?
Also, it would be referenced by many (15+) templates.
Many thanks.
<cfif listLast(CGI.CF_TEMPLATE_PATH, ".") is "cfc">
I am using this in my Application.cfc and its working. I use this becouse listlast(arguments.thePage,".") in onRequestStart returned error.
When I load my grid page, I get a popup with this error:
Error parsing JSON response: <wddxPacket version='1.0'><header/><data><struct><var name='TOTALROWCOUNT'><number>3.0</number></var><var name='QUERY'><recordset rowCount='1' fieldNames='ID,LOGINID,LOGINPW,LOGINNAME,LOGINLEVEL' type='coldfusion.sql.QueryTable'><field name='ID'><number>3.0</number></field><field name='LOGINID'><string>jaime</string></field><field name='LOGINPW'><string>xXxX</string></field><field name='LOGINNAME'><string>Jaime</string></field><field name='LOGINLEVEL'><string>Admin</string></field></recordset></var></struct></data></wddxPacket> [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]
After clicking Ok, I get this popup:
CFGRID: Response is empty [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]
Now, my dilemma is that I'm on a shared hosting environment and apparently the debugging is turned off. I've tried adding "?cfdebug" to the query string to no avail.
Now, if I perform a cfdump on the CFC using cfinvoke, I show this:
struct
QUERY
query
ID LOGINID LOGINLEVEL LOGINNAME LOGINPW
1 3 jaime Admin Jaime XxXx
2 2 liz Admin Liz XxXx
3 1 steve Admin Steve Fister XxXx
4 [empty string] [empty string] [empty string] [empty string] [empty string]
5 [empty string] [empty string] [empty string] [empty string] [empty string]
TOTALROWCOUNT 3
I don't know if this is the problem, but it looks like there are two rows of empty strings and I have absolutely no idea where they are coming from! Checking the db table, there are indeed only 3 rows in the table.
Any ideas? Thanks!
Thanks.
Steve
When I load my grid page, I get a popup with this error:
Error parsing JSON response: {Total rows:25.... [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]
After clicking Ok, I get this popup:
CFGRID: Response is empty [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]
My CFGRID looks likes this:
<cfgrid format="html" name="employeeGrid" pagesize=11
stripeRows=true stripeRowColor="gray" bind="url:employeeService.cfc?method=getData&page={cfgridpage}&pagesize={cfgridpagesize}&gridsortcolumn={cfgridsortcolumn}&gridsortdirection={cfgridsortdirection}&returnFormat=json"
delete="yes" selectmode="edit"
onchange="cfc:employeeService.editData({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="UserID" display=true header="Employee ID"/>
<cfgridcolumn name="FName" display=true header="First Name"/>
<cfgridcolumn name="LName" display=true header="Last Name"/>
<cfgridcolumn name="email" display=true header="Email" />
</cfgrid>
and my employeeService.cfc has this
<cfcomponent displayname="employeeService.cfc" output="false">
<cffunction name="getData" access="remote" output="false" >
<cfargument name="page">
<cfargument name="pageSize">
<cfargument name="gridsortcolumn" default="">
<cfargument name="gridsortdirection" default="">
<cfquery name="team" datasource="CMS">
SELECT UserID, FName, LName, email
FROM UserAccounts
<cfif gridsortcolumn neq "" or gridsortdirection neq "">
order by #gridsortcolumn# #gridsortdirection#
</cfif>
</cfquery>
<cfreturn QueryConvertForGrid(team, page, pageSize)>
</cffunction>
</cfcomponent>
Check to ensure CF Debugging is turned off.
I have a simple "Hello World"-type Flex page for testing. It calls a CFC which returns the string "Hello."
When the CFC resides underneath the following Application.cfc, there's an error because the OnRequest method still runs.
Naturally, when I completely comment out the OnRequest method, it works fine. The code in OnRequestStart just isn't deleting OnRequest, for some reason.
Here's the entire Appliation.cfc:
<cfcomponent >
<cfset this.name = "fred" />
<cffunction name="onRequestStart">
<cfargument name = "targetPage" type="String" required="true" />
<!--- ensure CFC / Web Service / Flex Remoting calls are not intercepted --->
<cfif listlast(arguments.targetPage,".") is "cfc">
<cfset StructDelete(this, "onRequest") />
<cfset StructDelete(variables,"onRequest")/>
</cfif>
</cffunction>
<cffunction name="onRequest">
<cfargument name = "targetPage" type="String" required="true" />
<cfinclude template = "#Arguments.targetPage#" />
</cffunction>
</cfcomponent>

As someone who has run into this problem a few times, I have to say I consider this a bug. I wonder if Adobe do too.