Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cf 9: cf ajax not compatible with Application.cfc?

Explorer ,
Oct 01, 2010 Oct 01, 2010

Hello,

Background:
I use the Application.cfc framework.  I like the onMissingTemplate, onError, and other functionality that it offers.  I've been working with Application.cfc since CF 7.

I started working on a project that required CF 9.  I wanted to use a cfgrid control and also some of the ajax features for a form.  I ran into problems with cfgrid right away.  The problem was with the bind attribute calling a remote funciton in a CFC.  Here is a sample of the error message that I'm able to get using the ?cfdebug=1 URL parameter:

JSON parsing failure: Expected '"' at character 2:'&' in {"page":1,"pageSize":10,"sortColumn":"","sortDirection":"ASC"}

Notice that somehow all of the double quote characters are getting transposed to be html encoded values """.  This is what the JSON parser is complaining about.

I switched tasks and started working on a simple form that used an autosuggest feature.  Then as I started testing this form, I ran into almost the exact same error:

JSON parsing failure: Expected '"' at character 2:'&' in {"vcSuggestValue":"5"}

After tweaking so many settings without any success, I decided to rename all my Application.cfc files and create a basic Application.cfm file.  It worked!

Next I tried to find out what was broken in my Application.cfc file as I thought that perhaps I had something screwed up.  I ended up down to a file like this:


<cfcomponent>
    <cfset this.name = "abc_admin">
    <cfset variables.dsn = "abc">

<cffunction name="onRequestStart" output="true" returntype="boolean" hint="Runs when a request starts">
    <cfargument name="targetPage" type="string" required="yes" hint="Path from the web root to the requested page." />


    <cfset request.dsn = variables.dsn>
    <cfset request.vcProductName = "abc.org">


    <cfreturn true />
</cffunction>
</cfcomponent>

As you can see the above Application.cfc file has almost nothing in it besides a couple of names and a datasource definition.  The cfgrid and autosuggest <cfinput> tag still do not work.

I took my project and moved it to a CF 8 server where these features worked fine.

I have tried to use Application.cfc on a CF 9 server running on IIS 6 and IIS 7.5.  Both of them fail so I do not believe that it is caused by the web server.

At this point I'm inclined to think that Application.cfc is broken all of the CF ajax features for ColdFusion 9.  If you have a solution to this problem, please reply to this message with an answer.  If you have ColdFusion 9, please try a simple autosuggest field on a form and see if it works with an Application.cfc based web site, please reply with your results.

Best regards,
Scott Jibben

3.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 01, 2010 Oct 01, 2010

You probably need to add a onCfcRequest() handler to your Application.cfc file...

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe821657cd7d6f83f6daaa733122cf6931bb-8000.html

--

Adam

Translate
LEGEND ,
Oct 01, 2010 Oct 01, 2010

You probably need to add a onCfcRequest() handler to your Application.cfc file...

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe821657cd7d6f83f6daaa733122cf6931bb-8000.html

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 01, 2010 Oct 01, 2010

Well, that does work.  Odd that the default onCFCRequest function doesn't work.

thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 01, 2010 Oct 01, 2010

Well, that does work.  [...] thanks!

No probs.

Odd that the default onCFCRequest function doesn't work.

Sorry, don't follow..?

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 01, 2010 Oct 01, 2010

Application.cfc is somewhat object oriented.  If you are missing the onRequest function in Application.cfc, you will use the onRequest that is built into CF and your pages will still work.

An Application.cfc can be this small and still work:

<cfcomponent>

    <cfset this.name = "abc">

</cfcomponent>

So, your site calls the built-in functions if they are not defined in the Application.cfc.

I also found that the onCFCRequest actually did not work and this is more complicated.

I need to take a break and come back to it to describe the problem better.

sj

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2010 Oct 02, 2010

Oh I see what you're driving at, however that's not really what's going on.

CF exposes some hooks to various events (application start, session start, etc), which the develop can apply handlers too (onApplicationStart(), onSessionStart() etc), which need to be put in a file Application.cfc.  But those handlers (written in CFML) are not extending (in the OO sense of the term) anything under CF's hood (written in Java), it's just an agreed-upon construct that CF will look for those event handlers and run them in the appropriate situation.  I mean... it's not like it's running those event handlers instead of the usual course of events, it's just some extra code CF will run for you in those situations.

As an example, try putting this in your onRequestStart() and see how far you get:

super.onRequestStart()

Hint: it'll just error because Application.cfc ain't "extending" anything.

The reason why people have problems here is because of the way onRequest() works.  You didn't mention it in your first post, but I imagine you had an onRequest() in your Application.cfc too?

The way one generally implements an onRequest() method is that it does whatever one needs it to do, and then does a <cfinclude> of the template name passed in as the argument.  Clearly that's not gonna work if the passed-in template is a CFC.  That's all that's going on.  It was easy enough to work around in CF8 by intercepting the request in onRequestStart() - which runs before onRequest() - and if the requested template is a CFC, then doing a structDelete(this, "onRequest") (and from the variables scope too).  Then there'd be no onRquest() to run, and the CFC request would have run just fine.  All CF9 does is if there's a onCfcRequest(), it runs that instead of the onRequest(), and instead of having to do all the structDelete() shenanigans.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 02, 2010 Oct 02, 2010
LATEST

Well, I did track this down.  I had been using the Portcullis project to protect against SQL Injection and XSS attacks.  I had placed this in the onRequestStart function.  This was breaking the ajax calls by replacing double quotes with the &quot; string.  This was caused by my mistake.

I did two things that made my project work correctly:

1. Moved the Portcullis calls to the onRequest function.

2. Added this Application.cfc to the root folder that contains the CFC's.

<cfcomponent name="Application" extends="ApplicationProxy">
    <!---remove the onRequest function--->
    <cfset structDelete(variables,"onRequest")/>
    <cfset structDelete(this,"onRequest")/>
</cfcomponent>

I have this file (ApplicationProxy.cfc) in my site root folder:

<!---Use this CFC to create derivatives (children) of the Application.cfc--->
<cfcomponent extends="Application">
</cfcomponent>

Not sure where I got the information about an extended Application.cfc/ApplicationProxy.cfc that removes the onRequest function.  Probably one of Ray Camden's or Ben Nadel's blog entries.

In the end I did not need an onCFCRequest function, just to correct my code.

Thanks for talking me through it,

sj

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources