views:

385

answers:

1

I've been playing with DWR and converters for a while and I really wanted to map my Java classes to JavaScript classes. Using DWR converters, I have the option to point out what is the name of my JS constructor given a Java class. So far so good... The problem arises when my JS constructor is within a JS package-like name (just like YUI's package system, eg my.beautiful.package.MyClass). DWR's current implementation doesn't allow me to use this kind of construct, giving me a SyntaxError when I try to use it. Is there an elegant way arround this limitation?

A: 

As far as I know the this isn't possible directly. I have in my current work project experimented with enhancing each returned object on the client side with methods from a Javascript class, which gets the result that I think you are interested in.

DwrService.getThings({
  callback:function(things){
    for(thing in things){
      YAHOO.augmentProto(thing, my.beautiful.package.MyClass);
    }
    // do your stuff here
  }
});

I'll have to check at work on monday (now is sunday) that augmentProto is correct one to use, but I think it is. There may even be a better hook into DWR that'll allow you to do this on the fly automagically.

Gareth Davis
One thing that I did, I "globalized" all needed constructors used by DWR, (using the notation as follows *my_beautiful_package_MyClass*) although it works, its not that elegant =/
Pablo Cabrera