?
Solved

Using application.cfc with cfajaxproxy

Posted on 2010-08-17
6
Medium Priority
?
841 Views
Last Modified: 2013-12-24
I've just migrated from using application.cfm to application.cfc, for now all i've really done is putting the contents of my application.cfm into the onRequest() function. Everything all fine and dandy except for code which makes ajax calls via cfajaxproxy.

The proxy code has a simple function:

<cffunction name="echo" returnFormat="json" access="remote">
   <cfset var response=StructNew()>
   <cfset response['status']='OK'>
   <cfreturn response>
</cffunction>

The callback code should be able to check for a json object response, however it now receives null in the callbackhandler function's argument. Anyone have any idea of what I can be doing wrong? Again, the only different is that i have replaced application.cfm with application.cfc. Should the onRequest() function return something? It currently has:

<cfinclude template="#arguments.page#">

.. which is for including the target page after my initialisation. Is something missing here, or can anyone suggest anything else i might be doing wrong?

0
Comment
Question by:paddycobbett
[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
  • 4
  • 2
6 Comments
 
LVL 1

Author Comment

by:paddycobbett
ID: 33462371
Ok, all I need to know is how to determine the page request type. I found some comments describing the onRequestStart function:

If you are using the OnRequest() method and you expect this application to be used for flash remoting or CFC-based web service calls, this is the ideal time at which to check for the request type (standard page request vs. web service) and if need be, delete the OnRequest() method from the Application.cfc (ex. structDelete(this, "OnRequest")).

So if i can determine if it's a webservice request type then i know to remove the onRequest function. Any idea of how to do this?
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 33462650
instead of doing that, you better migrate to a proper Application.cfc (not just sticking your old code into onRequest() method).  There is really very seldom that one would need the onRequest() method - other methods of Application.cfc are a lot better suited to various functionality.

e.g.
set all your application-wide vars in onApplicationStart() method.
session-level vars will be defined in onSessionStart()
request-specific vars can go onto onRequestStart() method.

You application will run a lot better this way, and you will have more fine-grained control over it. Plus you remote CFCs will start working :)

Azadi
0
 
LVL 1

Author Comment

by:paddycobbett
ID: 33472188
Thanks Azadi.. you know I suspected that may be the answer, however when i ported the code to the onRequestStart() method the variables I set via <cfset datasource="mydatasource"> were no longer available in my page via #datasource#. Would i be right in thinking that i should change all the references in my code to #APPLICATION.datasource#, and set this is onApplicationStart(), although there's quite a few variables in many pages I suspect this is probably what i should have done in the first place. Unless you disagree then is definately what i will do. Could i just ask before awarding deserved credit, when is the onSessionStart() function called? I typically create my session objects just after a loggin, so they would be set in the onRequestStart() method. It's not clear to me when the session starts, is it when a new client first hits a page within the application.cfc directory?
0
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 27

Accepted Solution

by:
azadisaryev earned 2000 total points
ID: 33474399
>> when i ported the code to the onRequestStart() method the variables I set via  <cfset datasource="mydatasource"> were no longer available in my page via #datasource#

in contrast to Application.cfm, which if fully processed before every page request, methods of Application.cfc get executed only at specific times. e.g. onApplicationStart() runs only before the first request to an application page after server restart; onSessionStart() method is executed once per user session when the session is created; onRequestStart() is executed before every page request; etc etc etc

also, since Application.cfc is a CFC, and its methods are functions, the variables you define within them will NOT automatically be available to all pages within your application. if you want a variable to be globally available, you need to define it in one of the persistent scopes (application/session/request) and then refer to it using the scope prefix. like you have already figured out, instead of <cfset datasource="mydatasource"> you would use <cfset application.datasource="mydatasource"> and then refer to the variable in your pages as #application.datasource#.

which scope to define the variable in depends on each variable and how you use it in your application. global vars (like datasource names, etc) which do not change a lot or at all will likely go into application scope. user-specific vars will likely go into session scope. page request-specific vars belong in request scope.

>> when is the onSessionStart() function called?

this method executes once per user session when the - with the first request to an application page from a specific browser. 'user' in session sense is not a person, but a browser (user agent) making a request to a page.
what would you define in onSessionStart() method? some generic session-scope variables, for example to keep track of user's login state, session start time, etc. you can also set/update application-scope variables in there (like increment session counter stored as application-scope var, if you use one).

if you use user authentication in your application and require users to log in, then session scope IS the scope to store user-specific data. like you say, these variables are usually set as session-scope vars in onRequestStart() method after the user logs in.

>> It's not clear to me when the session starts, is it when a new client first hits a page within the application.cfc directory?

yes, exactly. a session is created with the first request from a client (browser) to any page under Application.cfc

hope this helps you.

Azadi
0
 
LVL 1

Author Comment

by:paddycobbett
ID: 33478168
Azadi, great, that helped alot, and thanks for taking your time to explain so thoroughly =)

Ok, so that makes sense, the onSessionStart() will likely set up any generic session variables. I wasn't sure how i would set up any session variables specific to a user since i do not have access to their login details in onSessionStart() to be able to associate data for a particular user with data from the database, but what you said makes perfect sense.

So from you say, it's actually possible for a user to start a new session WITHOUT actually successfully logging in. A failed log in attempt for example would still hit a page within the application.cfc directory thereby calling onSessionStart() despite the fact that the application.cfc would likely subsequently forward the user to a login page outside that directory (correct?). With that in mind perhaps it isn't unreasonable to say that even generic session vars shouldn't be set in onSessionStart() but in the onRequestStart() method after a successful login. Surely even session start time should be recorded from when the user actually logs in, if infact he successfully logs in. Do you agree with this? If so i find it hard to justify why sites which require log-in would implement the onSessionStart() method.
0
 
LVL 1

Author Closing Comment

by:paddycobbett
ID: 33679516
Thanks alot =)
0

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

770 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