As hinted in my Running into Flex Limitations post, i finally managed to make a version of the rather nifty REST-based project object editor.
After being told about the magical “lzpostbody” parameter by Henry Minsky, i was able to send my XML data in the content of my POST request (which causes the Rails app to create Project objects).
Sadly i needed to make a little concession on the “PUT” method (which would cause the Rails app to modify the specified object) as i couldn’t manage to find a way of passing in the “_method=POST” parameter in from the request as i could with Flex, like so:
private function sendProjectUpdate():void
{
var projectUpdate:Object = new Object();
projectUpdate['name'] = pname.text;
projectUpdate['description'] = description.text;
updateProject.url = "http://localhost:3000/projects/" +
projs_dg.selectedItem.id + ".xml?_method=PUT";
updateProject.send({project:projectUpdate});
}
Doing a similar thing in OpenLaszlo didn’t work (my Rails app doesn’t seem to pick up the overriding _method). I can only assume that Flex is using some extra hocus pocus behind the scenes to make my app happy enough to go ahead. Maybe i’ll have to dissect the HTTP requests to get to the bottom of it.
To replace the requirement of “PUT”, i just added in another route in my Rails app that goes straight to the update method on the projects controller, like so:
map.connect 'test/update/:id', :controller => 'projects', :action => 'update'
map.connect 'test/update/:id.:format', :controller => 'projects', :action => 'update'
In any case, i was happy enough that i could get an equivalent version of my Flex app working in OpenLaszlo. Whilst it doesn’t have all the glitz and glamour of Flex’s components, it mostly still works the same, with the exception of the extra “Refresh” button which i had to add as i couldn’t seem to reliably determine when my requests to the server ended, which meant that the projects list doesn’t always automagically update to reflect the result on the server.
For reference, the code is located here.
UPDATE: Whilst this code works fine in the default PROXY mode, it seems that in SOLO mode the XML is escaped (e.g. ”<project><name>New Project (TEST)!!!!<”) when sending data, which more or less sucks.

Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)