Rob Gonda's Blog

ajaxCFC significant update: named arguments

I just uploaded a new release of ajaxCFC, and this one carries a rather significant update. I modified the way you pass arguments from JavaScript to your ColdFusion function. Before, due to that you were passing unnamed arguments, you were receiving them in a ColdFusion arguments array; Thanks to Kenton Gray's contribution now you receive all arguments as separate named arguments. The main seller was that you could have built-in validations ... I’m using metadata to retrieve the names of the declared arguments, and if you’re passing more arguments than you declare, they come in as ‘unkwnownXX’, xx being a counter or unknowns. I tested the code in CFMX6, 6.1, and 7, but not yet in Blue Dragon. If any of you could do that for me, it would be greatly appreciated.

Your old code WILL NOT WORK with the new ajax.cfc. You can make it work by one of two methods:
1)    name your arguments and their names in your CF Function. This method is the most advisable.
2)    2 :: the quick method) Remove the args declaration and use the arguments scope as an array by simple removing the args var… use arguments[1] instead of args[1].

ajaxCFC: small update for DevNet users

I just uploaded a small patch for ajaxCFC so it works with ColdFusion MX7 DevNet edition. As you probably know, DevNet adds a little annoying meta tag so you can't use it for production, but it also prevents you from generating anything other than html with ColdFusion, which is really lame.

Anyways, special thanks to Harry Klein for sending this fix. The callback handler has a regEx now that will check for that metatag and remove it prior to processing the response.

Canvas: open source ColdFusion wiki

Canvas initially was part of a Macromedia DRK, but today it went open source. It's a nice and simple ColdFusion Wiki, but just like any other Ray's projects, expect it to grow exponentially now that it went OS.

ajaxCFC will be using this Wiki, and I know it's missing some functionality right now, but I truly believe that it will be a great product in no time.

I set up the Wiki today and it's mostly empty :) but feel free to start contributing with anything you want: faq's, examples, docs, etc.

ColdFusion Open Source list now using ajaxCFC

The ColdFusion community open source projects list is growing, and there are several individuals helping the cause. Brian Rinaldi put together a very nice list of open source projects. After I changed my license, he chose to incorporate it to the site and use it for category filtering, and as expected, it's much faster than page reloads. Read how difficult was the experience from download to deploy on a very useful beginner's review of ajaxCFC.

ajaxCFC engine update

upon request, I just incorporated the latest changes from DRW's engine. It went from v1.76 to v1.83.

Below are the changes:

183. safari fix from 1.1
182. Fixing improper merging of call meta-data
181. make nested sync calls work properly
180. safari2 fix
179. experimental dwr filetype to help webstats
178. Rolled in fix for safari2
177. nested generic parameter handling

ajaxCFC License change

ajaxCFC used to be licensed under a restricted open source variation, but I realized that I was allowing everyone to use it anyways. I decided to avoid complications and license it under Apache 2.0

Enjoy

cfQuickDocs is officially using ajaxCFC

If you don’t have it bookmarked yet, visit http://www.techfeed.net/cfQuickDocs/ which I can assure you will replace your Macromedia / Adobe LiveDocs. You probably know LiveDocs is JavaScript based, with tons of redirects, slow, heavy … cfQuickDocs is a light-weight Ajax driven version with excellent structure and search abilities.

Thanks Jacob for this worderful tool, and check out his latest post about switching quickDocs from cfajax to ajaxCFC.

ajaxCFC: small bug fix

I just released a small bug fix for ajaxCFC: long queries were breaking the Ajax JS response because of unwanted carriage returns. Special thanks for Larry Reinhard for finding it and suggesting the fix.

Know your ColdFusion Server: ajax monitoring

Steve Brownlee put together a basic application that you can run to provide you with realtime graphs and charts displaying your JVM memory usage using AJAX, thus no page refresh. You have the choice of the following views.

1.    Total JVM
2.    Eden Space
3.    Survivor Space
4.    Tenured Gen
5.    Permanent Gen
6.    All memory spaces

In each view, you can choose to have the charts update every 2.5, 5, 15, 30 or 60 seconds. Having shorter intervals is great for when you are actively watching the memory to identify problems or monitor your usage, and then switch to long intervals for historical charts.

It's still in its first stages, but it’s free, growing, and has a huge potential to become a must-have tool for every ColdFusion Administrator. If Steve could add active threads, queues, cpu time, and keep expanding, I'll be running this tool 24/7.

check out the Orbwave Memory Explorer 0.1.103.

ajaxCFC for Model-Glue Explained

While this is not the final documentation, I know some people are starting to play with ajaxCFC/MG and my implementation is not straightforward. This is my first draft to get the feeling on how to document it.

Ajax.cfc is just another model in your MG application, used by the controller to manipulate data. You can initialize it in your Controller’s init function and store in persistently in the controller’s variables scope.

The Ajax remote request call flows exactly (or almost) like a traditional call. It flows as follow:

  1. Page triggers an AJAX request.
  2. The event will be caught by the MG framework.
  3. The MG event-handler will broadcast a message.
  4. The controller will pickup the message.
  5. The controller will AJAX model to parse it (onRequestStart)
  6. The controller can use other models at will (theEvent)
  7. The controller uses the AJAX model to prepare the reponse.
  8. The controller sets the ‘ajaxResponse’ value back to be used by the view
  9. The modelGlue.xml includes ajaxResponse.cfm as the view that will transmit the response back to the JavaScript callback function.

Alright, so this may sound complicated, but it really isn’t. The flow is exactly like any other page with the exception of:

  1. You need to parse the Ajax request with the Ajax model.
    1. You will received a structure with two elements

                                                              i.      id: the unique identifier of the Ajax remote call request

                                                            ii.      params[type array]: this includes all arguments passed by the JavaScript function. Because the arguments are unnamed, you will receive them in an array in the same order that they were passed.

    1. My example parses the values in the controller’s onRequestStart and place them in the request scope to be picked up later by the requested method.
    2. Optionally, you may invoke security and debugging functions contained in the Ajax model.
  1. You need to prepare the response before sending it back to the framework. You will use the Ajax.returnAjax method to do so. The returnAjax method always takes your response and the Ajax call unique identifier.
  2. You need to set the ajaxResponse value to be used by the view.
  3. Finally, include the ajaxResponse.cfm file that simply displays the ajaxResponse value sent by the controller.

Your JavaScript callback function will receive any response you sent as an argument.

That is pretty much the basis; nothing fancy, nothing different than what you usually do with the MG framework. Ajax.cfc is just facilitating the seamless communication between your JavaScript and ColdFusion side; that is all.

Note that the main event (the one making the Ajax call) needs to include the ajax.js file, the _ajaxConfig JavaScript object, and of course, your JavaScript calls and callback functions.

While I do not recommend leaving business logic at the client side, because it defeats the entire MVC and thus MG framework, it is the easiest way to get started with Ajax.

In my next example, I will show how to leave all the business logic in the server side, contained in views, and leave only connectivity functions in the client side.

If you have any comments / requests, do not hesitate to comment or contact me and I will do my best to add them to the framework.

More Entries

This blog is running version 5.9.003. Contact Blog Owner