Building on WordPress with Dojo - Kill me now

A project I'm currently messing with for WordPress has me delving more deeply into the XmlHttpRequest arena looking for something standard and well-maintained that I won't have to tweak to incorporate. Matt suggested I try Dojo for this purpose. After speding a little more time looking it over, I was impressed enough with the workings of the library to attempt a test project (yet another WordPress plugin) using Dojo to do transparent server commuincations from the browser. This is that story.

Before I continue, note that I have been working completely on my own on this for less than 24 hours. These are initial unedited impressions of the whole toolkit, which I find (when I do finally get it working the way I want) should work marvelously for what I want to do. I haven't bothered to contact the developers (yet) nor have I tried to read through all of the weightier (code-wise) mailing list archives. I don't want to get on anyone's bad side (particularly the Dojo devs) for saying bad things about anything, so I want to say explicitly that this is my story, as daft as I might have been following the path I did, and not a conclusion about how good/bad anything is. Your mileage will vary as a result of not following in the path of my own stupidity. Learn from my experience and avoid suffering.My story begins yesterday afternoon. I had a downloaded copy of the initial Dojo release and was jumping up and down on it to fit it into my square hole. The plugin required that a form be submitted to the server without telling the user about it. It wasn't a difficult task, and I didn't care what the values sent to the server or returned from the server contained at the time. Everything worked fine, and I was encouraged by my success. Then I moved to a new computer and things started to unravel.

When I started to care what data was going to the server, that's when my problems started. I must have spent four hours trying to figure out why the form was not being picked up by the server code. I think that my problem mainly stems from something odd in a WordPress

$wpvarstoreset loop and my inference that the form's method was going to be used by Dojo as the submission method. Being unable to find Dojo documentation of any useful length (several of the bindArgs structure elements seem completely undocumented), I tried delving into the code. I learned a few things about the __package__.js that comes in the initial release. First, it doesn't seem very recent. Many additions have been made to the code since that initial release, including something vital to my success (more later). The latest release is available via SVN. Second, the __package__.js file is a compressed version of a bunch of other files from the Dojo library. You don't want to mess with the source in __package__.js, but the source that it's built from. Don't hurt yourself on the sharp edges of the release package. I fought with WordPress for a bit. My form was submitting via GET no matter how I tried to get it to use POST. This was a problem because the data I was submitting could be quite long, and WordPress didn't seem to like that my data was coming in via GET. Looking at the Dojo source (in its compressed form, mind you - not really understanding what the heck was going on there) I saw that XmlHttpRequest via POST was not available. Fortunately, I found some information online that suggested that this functionality had been added in a SVN commit. So I looked around for the SVN repo, and finally found that. But the source wasn't in the same format as what I had. Indeed, it seemed as though I would need to add many directories full of javascript source files to enable my plugin. This wasn't good. Some more searching yielded information associating Dojo to Apache ant. Ant is a built tool made in Java. It's kind of like make. As I currently understand it, you use ant to turn all of those directories of source files into the single __package__.js file. Neat. Well folks, I'm not a *nix binary coder. I have only rarely used non-Microsoft make tools, and only when I had complete instructions. So at about 1:30am, things were looking pretty bleak. I decided to get rest and then come back at it. This morning, I've gathered all of the information for making this work on Windows. I've installed Python (which seems to be used in the builder) and Ant. I seemed to already have a JRE installed, so I didn't actually need to download that. I used SVN to checkout the latest Dojo. I added my Ant bin directory to the PATH. I added the environment variable ANT_PATH=C:\ant because the Ant docs said it was needed. I opened a console window, changed to the Dojo checkout directory, and ran ant. There were errors, which the Dojo build script says is ok. I ran ant again, and got some options. Hmm... I picked the obvious option, and ran ant release, which did produce output in the release directory. I looked at the __package__.js that was created, and was disappointed to see that there was still no POST method used anywhere in the source. Remembering something I had read online during my many searches, I poked around the Dojo build directory into the profile section. I saw a profile there for what I wanted, browserio.profile.js. But how to enable that profile? Here's the command line you want: ant -Dprofile=browserio -Ddocless=true release

And now the release package has source for POST via XmlHttpRequest. Whew. But does it work? Not quite.

The library seems to be built correctly, but it still needs some work to get it to do what I want. It is now using POST for all requests, regardless of what I try to tell it to use. I think this may be because I'm specifying a form to submit and the method of the form is POST (which is ironically what I originally wanted it to do). Now it's ignoring the URL that I tell it to post the form to, which is very inconvenient. Maybe it was doing this before, but I didn't notice since I was submitting the form to the same script that normally processes it. But in this new case, I want to send the form to a separate processor so I can return data appropriate for Dojo to use. It's not doing this. I may need to tweak some parameters, which - as I said earlier - seem largely undocumented.

Ah, well. I'll figure it out eventually. I was hoping everything was going to work fine by the end of writing this and I would be able to post the new plugin, but not so much. If I'm lucky, it'll be later today. If not, who knows.

At least after playing with this, I'll have a much better grasp of Dojo and how to apply it to the other thing I'm writing for WordPress, which will have to be less experimental on the first try.


7 Responses to Building on WordPress with Dojo - Kill me now

  1. Stephan Segraves from badice.com 2005-04-20 10:47:05

    Not sure if this fits your needs but have you looked at SAJAX? http://www.modernmethod.com/sajax/

    It sounds similar to Dojo but a lot easier to use and it supports POST vars.

  2. Owen from www.asymptomatic.net 2005-04-20 11:27:43

    I have seen it and from what I can tell it suffers from some fatal flaws (for me, not necessarily for anyone else):

    1. It requires server-side code to build the client connection. You can't include a static javascript file to incorporate the AJAX functionality, nor can you post forms to URLs other than the one used to call the core javascript output.

    2. It doesn't fail-over to other transports (iframes, for example) when XmlHttpRequest doesn't exist. Granted, Dojo doesn't do this either (although I didn't check this after the rebuild so maybe it does now), but it's in the roadmap.

    3. The license is unclear or unavailable.
    I need something GPL-compatible. The author of SAJAX thought enough to copyright everything, but not enough to provide a distribution license. That leaves me feeling uneasy about including it in anything.

    Maybe SAJAX is a lot easier to use, but it's not as complete.

  3. Stephan Segraves from badice.com 2005-04-20 11:33:12

    Good points but I have one question, why do you have all of that server side stuff for Dojo? I haven't used either Dojo or SAJAX, though I have read good and bad things about the latter. There is also another project that is in very early stages called liteAJax http://golem.digitalhymn.com/?p=ajax

  4. sdf 2005-04-21 13:50:25

    according to sajax' website, it is licenced unter the BSD licence (in the FAQ section)

  5. Owen from www.asymptomatic.net 2005-04-21 14:19:28

    There isn't any server-side stuff required for Dojo (unlike SAJAX, it seems). Just code whatever server-side script you need to handle the request and pass back data in whatever format feels comfortable to you.

    Hmm, I guess you don't need to include the BSD license with the distribution?

  6. Alex Russell from dojotoolkit.org 2005-04-25 10:19:05

    Hi, This is Alex Russell, one of the commiters to Dojo.

    After reading your post, I want to encourage you to mail me (alex@dojotoolkit.org) or subscribe to the dojo-interest mailing list (http://dojotoolkit.org/mailman/listinfo/dojo-interest). I promise we don't bite.

    I apologize that the build process is really opaque, and I'm sorry that it's caused you pain. We know that we need more public information, and have opened up the Dojo wiki as a result (http://dojo.jot.com). Perhaps you'd be willing to contribute a walkthrough of the process you went through to get up-and-running to the wiki?

    Anyway, like I said, send me mail if you have any other problems. I want to make sure that this isn't painful for you. We should easily be able to get your GET/POST issue worked out.

    Regards

  7. Andrew K from leftjustified.net 2005-05-05 00:22:06

    The above comment is what I love about open source and the web standards community :)

    Can't wait to embrace a slightly more mature version of Dojo! (already gave it a try...)

1185