As a heavy user of Rob Gonda’s ajaxCFC library, I’ve incorporated it into almost every app I’ve written in the past two years. The only restriction that required me to write workarounds was the fact that you could only invoke ColdFusion Components directly. The thing is, I also love ColdSpring to manage dependencies and to implement my Aspect Oriented Programming components.
What I want is to be able to call my ColdSpring beans with ajaxCFC so that I can make my asynchronous calls, get serialized data back, and all the while utilizing the dependencies set up in my beans. Well, I finally got around to modifying Rob’s code to allow for this. I use the jQuery branch, so my solution currently only works for that implementation. I may try to work on the DWR version, but that’s unlikely because I don’t use it.
There are three changes to how you invoke ajaxCFC in order to work with ColdSpring beans.
Instead of the URL value being the path to your logic component, its value should be the path to the ajax.cfc component
url:'com/company/common/ajax/ajax.cfc'
This property’s value will be the name of the ColdSpring bean you want to use.
bean: 'Facility'
This property’s value will be the name of your ColdSpring bean factory.
factory:'application.beanFactory'
Here’s a sample call stripped directly from one of my applications
$.AjaxCFC({
url:'com/company/common/ajax/ajax.cfc',
bean: 'Facility',
factory:'application.beanFactory',
method: 'getFacilities',
data: { 'orderby':orderByField },
useDefaultErrorHandler: false,
success: function(results) {
$('#facilitySelectContainer').html(results);
},
error: function(results) {
Ext.MessageBox.alert('Error Notification', 'There was an error while loading the facilities. Please try again.')
}
});
There are two files you need to replace.
2 Responses for "Invoking ColdSpring beans with ajaxCFC"
[...] got a ColdFusion Component returning a query object, which is then converted into JSON with the ajaxCFC [...]
[...] I’ve been using the AjaxCFC library for years. It’s my preferred way of integrating Javascript and ColdFusion via AJAX. I’ve even modified it from its original form so that my implementation was strictly for integration with jQuery, only returns JSON strings (ignoring WDDX and simple string), and can work with ColdSpring. [...]
Leave a reply