Rob Gonda's Blog

uploading a file via Ajax

It is not possible.

Lol, well, ok.... the XMLHttpRequest cannot send multipart/form-data, therefore, cannot upload files. There are two ways around this:
1) use an iframe. This can be transparent, e.g. using the dojo.io.bind will do it automatically.
2) use a pixel Flash movie. You can create a 1 pixel flash movie, interface with it using the external interface (Flash 8 required), and use the Flash buffer classes (Flash 9 required) to upload the file. The nice thing about this is that you get the total bytes transferred count, thus you can display an accurate progress bar.

I'll try to post an example of both options soon.

CFUnited - Ajax Intensive for ColdFusion Developers

I gave an 8-hour class last week at CFUnited, geared towards Ajax Development for ColdFusion. As promised, you can find here all the material used, including slides, additional listings, and source code.



To run the source code, simply copy the cfunited folder under your web root. All examples should run without additional settings. To run the ajaxCFC / Model Glue examples you may use MG 1.1 or MG:Unity, which requires ColdSpring and Reactor, which are all included.

p.s. special thanks to Joe and Ray for publishing the prototype and spry examples.

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.

Dojo Toolkit and ColdFusion

This came up in an entry I blogged the other day: What if (i/we) write a ColdFusion library to interface with the Dojo toolkit? Dojo is the best JavaScript toolkit out there, very complete, and it's only going to get better. They keep adding neat features, and they're the main library to be used for the Open Ajax Initiative, which include IBM, Eclipse, Google, Mozilla, Yahoo, and others. It's actually the only JavaScript library that includes widgets, an ajax engine, low level effects, ... They just added offline storage though the use of the Flash Platform...

So the raw idea is to develop a ColdFusion library to allow developers to easily implement Dojo Widgets and use the Ajax library, which by the way supports cross-domain scripting now ... Dojo supports Ajax calls through the io, rpc, and json classes. Documentation and examples are limited, extremely limited, but the idea is to make the server side communication transparent for the developers, kind of what I did with ajaxCFC.

The Dojo IO class already supports data binding, back button fixes, bookmarking though URL state changes, the form serialization I posted last week, and more...

It would be great if I can manage to distribute this load among a few contributors... this could be huge... the ColdFusion community will love us forever. Think about it, not only for it's Ajax features, with it has an amazing amount of widgets and ui interfaces...

Thoughts?

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.

JSMin for ColdFusion

JSMin is a utility to compress JavaScript by removing unnecessary whitespace and comments. Unlike obfuscation, it doesn't rename any of your variables or functions, leaving the core functionality intact. Depending on amount of comments, this utility may save from 50-80% on file size. Here's a good Minification Vs. Obfuscation article.

Darryl Lyons released CFJSMin, a ColdFusion utility to compress JavaScripts. I'm not sure why would you want to compress your scripts from a server side scripting language instead of running a binary executable... I guess that if you have a source folder and production folder you could automate changes... CFJSMin also has the ability of taking several input files and save them all in a single compressed file. This is good for caching.

Darryl, if you're reading this, here's a request: I'd like the tool to read several JS files as input, but instead of writing a target file, I'd like the output in a variable.

In addition of compressing your files, take a look at gzip and real time data compression. Here's a good article on how to set your IIS to compression. For those who run apache, I know it's really easy, but I don't have the information handy.

CFLive! AJAX for ColdFusion Recording

I did my CFLive presentation today ... let's clarify --again-- that it was only a sneak preview of CFUnited, not a class, demo, or tutorial... I didn't talk about ajaxCFC or any particular implementation. I listed all the topics I'm planning to cover at CFUnited, did a quick Ajax overview, and showed a few examples... The Breeze presentation was recorded and it is available for everyone.

You may also download the slides if wish.

Why Spry: Kevin Lynch answered me

A few days ago, I posted an entry asking why is Adobe entering the Ajax world? I just found this entry where Kevin explains the main idea.


You have to be pretty good at knowing code to use the frameworks. So what we worked on here [in Spry] is how can we get designers more involved in Ajax?
Kevin Lynch
Chief Software Architect, Adobe Systems Inc.

The idea seems to be that Adobe wants to reach designers, not developers. Kevin claims that a designer can use this framework and implement Ajax sites / widgets, thus enhancing the user experience without coding. The Spry framework allows you to retrieve remote dynamic data by using a data binding mechanism, to which some Flash developers are familiar. This approach doesn't fully exploit the advantages of Ajax, and I'm not sure if it even provides any. Can someone think of how a designer could use this framework and why should he even care? I'm not trying to discourage Adobe, this _may_ be a great idea, but I'm blind. I guess I'll have to wait and see how a designer takes advantage of it and show me how Ajax makes him stand above the competition ...

Does anyone have a different point of view?

Dojo 0.3.0 Now Available

Dojo 0.3.0 was released with many new features. Dojo must be the best JavaScript library, it really makes me think if I should rewrite some ColdFusion components to generate Dojo widgets and Ajax binding ... sounds like a great project too me, if you're interested drop me an email.

At the Ajax Experience, Alex demonstrated a new use of the Flash Platform with Ajax: storage! Flash has be ability of storing large amount of data local objects, which is something like a Flash Cookie. By default you can store 300k of persistent data, up to 500k. Dojo makes use of this storage transparently by using a 1px flash component ... really neat.


The latest release of Dojo has a slew of new features, including:

  • Less boilerplate when writing widgets
  • A new lightweight animation system that makes using and building animations dead simple
  • Tested, high-performance local storage engine
  • Cross-domain Ajax support and cross-domain package loading
  • The ability to bundle CSS as well as HTML in profile builds
  • Better performance
  • New widgets:
    • SortableTable
    • TitlePane
    • Form validation
    • Menus and menu bars
    • Google and Yahoo maps
  • And more than a hundred other bug fixes and improvements.

More Entries

This blog is running version 5.9.003. Contact Blog Owner