Friday, October 5th, 2007

Joe Walker shows a tip from DWR.Next

Category: DWR, Java, JavaScript

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.

  1. public class FileUploader {
  2.   ...
  4.   public BufferedImage uploadFiles(BufferedImage uploadImage, String uploadFile, String color) {
  5.     uploadImage = scaleToSize(uploadImage);
  6.     uploadImage = grafitiTextOnImage(uploadImage, uploadFile, color);
  8.     return uploadImage;
  9.   }
  11.   ...
  12. }

But a BufferedImage means nothing to JavaScript, but that is fine… in JavaScript land you just use the nodes (or so you think).


  1. function uploadFiles() {
  2.   var image = dwr.util.getValue('uploadImage');
  3.   var file  = dwr.util.getValue('uploadFile');
  4.   var color = dwr.util.getValue('color');
  6.   FileUploader.uploadFiles(image, file, color, function(data) {
  7.     dwr.util.setValue('image', data);
  8.   });
  9. }

Anyway, let’s watch Joe explain:

Posted by Dion Almaer at 7:59 am

3.7 rating from 19 votes


Comments feed TrackBack URI

Who’s “Joe” and what is “DWR”?

Comment by Ted Turner — October 5, 2007

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.

Comment by david — October 5, 2007

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.

Comment by Scott Schiller — October 5, 2007

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.

Comment by Kris Zyp — October 5, 2007

@Scott, Kris: Don’t suppose you know where to find those presentations do you? :)

Comment by volve — October 5, 2007

Leave a comment

You must be logged in to post a comment.