« Return to Thread: Excluding properties when converting from JavaScript to Java objects

Re: Excluding properties when converting from JavaScript to Java objects

by David Marginian-2 :: Rate this Message:

Reply to Author | View in Thread

I am a bit confused.  If b is not a part of Foo why are you setting it in
your JavaScript object?  

Original Message:
-----------------
From: Bruno Klava bklava@...
Date: Thu, 17 Apr 2008 16:33:17 -0300
To: users@...
Subject: Re: [dwr-user] Excluding properties when converting from
JavaScript to Java objects


> > Using black-lists in dwr.xml only excludes properties when converting
from
> Java objects to JavaScript objects.
> Are you sure? I wasn't aware of this although the docs do only mention
that
> getters are excluded.

Sorry. I should have explained it better.
I meant that black-lists doesn't prevents DWR from sending data from
JavaScript object properties that not match the corresponding Java
class.

For instance, if you have a class Foo

public class Foo{

     private int a;

     public Foo(){
     }

     public int getA(){
          return a;
     }

     public void setA(int a){
          this.a = a;
     }

}

a class Bar with a method saveFoo(), exposed through DWR,

public void saveFoo(Foo foo){ ... }

and you have the following JavaScript code:

var jsObject = new Foo();
jsObject.a = 123;
jsObject.b = 456; // b is not part of Foo prototype!
Bar.saveFoo(jsObject, callbackFunction);

DWR sends to the server:

c0-scriptName=Bar
c0-methodName=saveFoo
c0-id=0
c0-e1=number:123
c0-e2=number:456
c0-param0=Object_Foo:{a:reference:c0-e1, b:reference:c0-e2}

and it doesn't matter if you change the converter to exclude the property b:

<convert converter="bean" javascript="Foo" match="my.package.Foo">
     <param name="exclude" value="b"/>
</convert>


Althought b is, obviously, never setted in th foo object passed to the
saveFoo method in the Bar class, the property is always included in
the data sent to the server.



In my case, the "b property" is a div element with hundreads other gui
elements, so I get the "Max depth exceeded when dereferencing ..."
error. What I need is not to send these properties data to the server,
without setting then to "undefined".

I hope my problem is more clear now ;)


Thanks,
Bruno

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



--------------------------------------------------------------------
myhosting.com - Premium Microsoft® Windows® and Linux web and application
hosting - http://link.myhosting.com/myhosting



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

 « Return to Thread: Excluding properties when converting from JavaScript to Java objects