Rob Gonda's Blog

Ajax Debugging Tip

Rey Bango posted a nice entry to help debug Ajax calls. The problem people usually run into is that Ajax triggers a remote call in the background and they have no idea to see why it failed. ajaxCFC will show you the ColdFusion error, if any, but if the problem breaks to communication for some reason it will just say invalid reply from the server... but why?! I always tell people to install a nice http sniffer, and Rey confirms it.
The moral of the story is: use Firefox, use FireBug.

ajaxCFC update 0.73

ajaxCFC has been updated.

The first change is a fix for the problem experienced by some people when sending the & sign by textareas or the suggest example.

The second change is the ability to send named arguments. It works now similar to how flash remoting does: if you send a single argument in form of an object, it will be passed as a collection instead. You may still pass unlimited arguments and ajaxCFC will match them to the expected named arguments in order, but this will be a problem if some of them are optional.

Example:

DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'method', arg1, arg2, arg3, result);

This string will invoke a method passing three arguments, which may be named in your function, but have to be in a specific order.

DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'method', {"cfarg1": arg1, "cfarg3":arg3}, result);

This string will invoke the same method passing only two out of the three arguments.

ajaxCFC update for Model Glue and MachII

I previously released some examples of Ajax for Model Glue, including port of the Contact Manager example that works with Ajax and XML Sockets. I missed to consider that most people will not be able to get the XML Socket server running, thus not being able to run this example on their servers. Added another example that uses only Ajax, without the sockets complication ... if you diff both versions, you'll find that I only changed a single line in the config file to use an ajaxLayout instead of socketLayout ... nonetheless, this should allow you to run this example out of the box ...

And the moment everyone has been waiting for: ajaxCFC for MachII is out thanks to Dan Wilson! He did a great job taking the same Contact Manager example and porting it to the MachII framework. His implementation is really clean, using Plugins and Filters to extend the MachII framework, not to mention that the layout he built for the example is much prettier than mines :)

The code is really clean and should make sense for every MachII developer. I'll try to write some documentation and instructions, but that will take some time. Sorry for delaying this post Dan, I really appreciate your contribution and so does the CF Community.

Enjoy.

ajaxCFC Update: addOptions() - serializeForm()

I just updated the ajaxCFC distribution files to include an update to the addOptions() utility. The y! group has been talking about passing a CF Query to the addOptions() function for a few weeks and thanks to the contribution of Jeff Lester it's possible now. It behaves exactly like the addRows() function, where it takes _cell_ functions to get the value and text of the returned query. It is usually easier to learn by example, so check out how it's done.

Additionally, some of you must be familiar and frustrated with the lack of ability of passing an entire form as an object; if you try, you'd get an maximum recursion error. I wrote a small function in my contact manager example that takes a form and serialize it into a JavaScript object, so I chose to include it into the DWRUtil namespace... You can now call x = DWRUtil.serializeForm(document.frm) and pass it to your Ajax call.

ajaxCFC update for Blue Dragon Compatibility

It's been a while since my last ajaxCFC update, but my last release had a small bug when running in Blue Dragon. It seems like the getMetaData function doesn't behave exactly the same, so thanks to Vience's help I fixed it to work with BD too.

I also have a port for the Mach II framework coming really soon thanks to Dan Wilson. Don't you love open source projects?

MVC'ing and Ajaxifying BlogCFC : interest?

I know Ray just announced the development of BlogCFC 5.0, and I really admire and respect Ray for his contributions to the CF community. I just came up with the idea of porting blogCFC to an MVC framework, not Model-Glue, but a methodology that I use every day and it has proven to be extremely scalable to me. I also use ajaxCFC with my framework, and will be adding Ajax components to the blog; it won't be a one page RIA, but only small usability elements that would be nice to have.

So the question is ... should I wait until Ray released blogCFC 5, or should I branch it to a new version, using MVC and Ajax, branch a new open source project, and write a journey of my project ... again, just like Ray did with the Model-Glue series .. you see Ray! You're an inspiration :)

I'll take votes, hehe ... I know I want to write this, but I'm skeptical about missing some nice additions once the new version is out. It will be impossible to migrate those without rewriting them too.

Who votes for branching now and says wait? please back your side...

ajaxCFC suggest example

I've been saying I'll post this for far too long ... The code is still not at the point I would like it to be before it's released, but it's working and the community could make use of it; plus, as usual, you can suggest changes and fixes ...
I added a suggest example and sample code in my ajaxCFC project page. Enjoy.

**Special thanks to John Schroeder for his contribution to this code.

Slides for the SEOMUG Spring Conference

I just got back from dinning with Jeremy Geelan, a really nice guy I must insist. He gave a keynote at the conference, and I had two sessions. We had about 300 delegates, not bad at all. It was indeed the best conference and value ever for the $25 cover fee ;)

My first session was ajax101, a kickstart providing you all basic information on AJAX. The second, was an ajax301 (yes, I skept one) providing a higher level AJAX solution, using ColdFusion, Model Glue, AjaxCFC, and optionally XML Sockets. For this second session, I showed how to develop Ajax application without coding a single line of JavaScript (for some basic examples). Furthermore, you could reuse 100% of your traditional html application, including models, controllers, and even the views.

You can download the slides I used for the sessions, and I'll compile the examples I used soon too. Most of the examples are available though my ajaxCFC download, including all the Model Glue examples, sockets, etc ... except the Model Glue framework itself. I should make a copy available anyways, because I use a BER (head version on an svn server) version for all my examples.

I mentioned in my sessions that I will do my best to answer all questions and emails, and I keep my word. Please comment here or if it's too lengthy, just drop me an email.

I hope you enjoyed the sessions as much as I did.

p.s. more on other sessions and pictures to be posted soon.

Download slides for ajax101 and ajax301.

Behold Model-Glue users! MG+AJAX Made easy

I just released a new improved version of ajaxCFC for the Model Glue framework. Now it's even easier to add Ajax to your robust ColdFusion MVC applications. I modified the Echo Example and added a Contact Manager Example to show how it works. All open source and included in the ajaxCFC download. The contact manager example is the same that comes with Model-Glue, using the same controller, models, and views ... slighly Ajaxified :)

[Updated] IMPORTANT NOTE: The XML Socket works on port 1225, so if you're behind some firewall preventing that traffic you will not see the refreshes. I am still working on some port 80 proxy, but for this experiment just open that port.

btw, I will be demonstrating all this at the upcoming Spring Conference, this week.

If that wasn't enough, included is also the next level of Web 2.0 applications; a mash-up of ColdFusion / Model Glue / ajaxCFC / XML Binary Sockets / CF Event Gateways... This combinations allows you to only for your presentation layer to interact with the server in the background, but also for the server to push data to the clients. No more Ajax pulls every 3 seconds interval, now the server can just broadcast the command to all clients. I shall call it Apocalypse. ;)

I modified the Contact Manager example that comes with model glue to use Ajax and Socket servers... now every time anyone adds/edits/deletes a contact all clients' views will get updates... just imagine the possibilities. Just try it yourself... open two browsers and see them interact.

I will try to briefly explain the framework the best I can.

First, you need the BER version of the model glue framework; Joe still hasn't officially released MG v1.1.

Now, the framework consists of a model: ajax.cfc, some JavaScripts included in the views/js folder, and a rendering view ajaxResponse.cfm. That's it...

How do it work...
The examples that come with Model-Glue use a private Layout hanlder, so I just added two more: AjaxLayout and SocketLayout... Now every time you need to respond an Ajax request you use the AjaxLayout, and if you want to broadcast something through the socket, you use the SocketLayout.

I modified the controllers init and OnRequestStart to parse the Ajax request... once it gets to your controllers handler all Ajax vars will be sent to you as regular event values, which you can get with getValue. There's not much more you need to know there...

Your controller will do its thing and set vars to be used in modelglue.xml ... now, here's the beauty ... when you use the AjaxResponse renderer your views will modify DIV Layers, or anything with the view's ID ... For example, if your body has a container calls contentForm, once you render a view with that name, all content will get placed inside that DIV...

If you need to run scripts you can use a reserved view name: 'script'. If you create a view with that name, all code inside that view will get evaluated in the client side. I modified the Echo Example to use this method so you can see what I mean.

The socket implementation is still in alpha mode... I just finished the prototype today... how does it work?!

I added a 1px Flash movie that weights only 1k that all it does is to open a socket connection to a ColdFusion Event Gateway. I rewrote the XML Binary sockets that comes with CFMX7 to better suite the Flash XML Socket protocol. I also added a few methods such as onConnect and onDisconnect. Anyways, when you need to talk to the server to do it through Ajax, but if the server needs to talk to you, it will do it through the XML Gateway. The beauty is that you do not need to modify anything or create any custom handler for it ... The flash movie uses FS Command to communicate with JavaScript and triggers the same calls the Ajax response would, so the same rendering in the server works for either method.

I included the org.gonda.socket.jar file, which would have to be registered as a custom event gateway to make the contact manager example to work. Just point your JVM class path where the file is, restart ColdFusion, and register a new gateway:
Name: FlashSocket
Class: org.gonda.socket.SocketGateway

Then create a new instance and call it 'flashSocket1'. I provided the cfg file in the example too.

In the main view, both IP and port are passed to the Flash file as FlashParams... will easily see how to modify it.

I know, you are thinking it's too much, but it's not THAT complicated ... and it's well worth it ...

Ok, so what is the catch? There are a couple of issue I still need to work on ... one) The socket binds itself to an IP and port, and I don't want to create a new socket for every application.. especially if I need to open a new IP on my firewall every time ... two) firewall... yes, I need to find a way to perform http tunneling, or to detect that it was blocked on run time to shift all socket calls to Ajax.

I know it's not crystal clear, but I wanted to get it out there and get people thinking ... I'll try to document it better this week before the conference.

ajaxCFC: DWR AddRows function improvement

I just released a small modification, but largely requested by the community: cell Renderers....

As the matter of fact, Kenton Gray came back to the rescue, he modified utils.js and wddx.js, so if you're upgrading, you only need to load those two files. You can check the new use with the same Query Example I posted before, but this time it adds some custom cell functions. Now you can send queries back from CF and easily populate tables with any custom code.

This is the true spirit of open source. Thanks Kenton! if anyone else has any suggestions or contributions, do not hesitate to drop me an email.

More Entries

This blog is running version 5.9.003. Contact Blog Owner