Friday, October 5th, 2007
Joe Walker shows a tip from DWR.Next
<p>I asked Joe to show us something interesting that he is playing with on DWR and he quickly obliged by showing us a new file upload and download feature that allows you to do new fancy things with files.What is cool about this is that the APIs from Java and JavaScript lands feel right in each, but to do this DWR has to do a lot of fancy work to hide the details.
In Java land you write something like the following, which uses Java BufferedImages.
-
-
public class FileUploader {
-
...
-
-
uploadImage = scaleToSize(uploadImage);
-
uploadImage = grafitiTextOnImage(uploadImage, uploadFile, color);
-
-
return uploadImage;
-
}
-
-
...
-
}
-
But a BufferedImage means nothing to JavaScript, but that is fine... in JavaScript land you just use the nodes (or so you think).
-
-
function uploadFiles() {
-
var image = dwr.util.getValue('uploadImage');
-
var file = dwr.util.getValue('uploadFile');
-
var color = dwr.util.getValue('color');
-
-
FileUploader.uploadFiles(image, file, color, function(data) {
-
dwr.util.setValue('image', data);
-
});
-
}
-
Anyway, let's watch Joe explain:
Related Content:











Who’s “Joe” and what is “DWR”?
If you’re stuck in Java-land, DWR (Direct Web Remoting) is a dream come true. It lets Javascript be Javascript, and the Java side never knows the difference.
I doubt that it’s a compelling reason to bet the farm on Java, though, if you’re already productive on some other platform.
Joe also gave a pretty cool/disturbing presentation with Jeremiah Grossman at the SF Ajax Experience on web security. I can’t speak for the Java side, but browsers are pretty bare-bones when it comes to handling files via form elements.
That presentation on security was my favorite from the conference, I loved the stuff on anti-DNS pinning, when they hacked into the router using JS and were able to remotely send JS code directly to the hijacked browser.
@Scott, Kris: Don’t suppose you know where to find those presentations do you? :)