|
View:
New views
13 Messages
—
Rating Filter:
Alert me
|
|
|
Excluding properties when converting from JavaScript to Java objectsHi,
Is there any way to exclude some object 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. In my application, the user can modify the data structure using gui elements (in a way that I need a reference from each gui element to the actual object and vice versa) so, when sending the data to be saved in the server, I get the "Max depth exceeded when dereferencing ..." error due to the references to gui elements. My currently workaround is to navigate through the entire structure and, for each object, set the reference to the gui element to "undefined". Then, after sending the structure to the server, I need to reload it to get the references to gui elements back. (I could store these references in temporary elements to be reassigned to the objects after communicating with the server, but the structure is quite complex to do so). Any suggestion is welcome. Bruno --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: 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. http://getahead.org/dwr/server/dwrxml/converters/bean A work around could be to have two classes for your bean. Lets call them BeanAll and BeanRestricted. BeanRestricted has only the setters you want to convert from javascript. BeanAll extends (or delegates to) BeanRestricted and has the other properties needed on the serverside. Cheers, Lance. On 16/04/2008, Bruno Klava <bklava@...> wrote: Hi, |
|
|
Re: 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@... |
|
|
|
|
|
Re: Excluding properties when converting from JavaScript to Java objects> I am a bit confused. If b is not a part of Foo why are you setting it in
> your JavaScript object? It's a gui element representing this object (the user can manipulate the data using the gui elements, and the structure is quite complex, so i need a reference from each element to its gui element). --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
RE: Excluding properties when converting from JavaScript to Java objectsI've had the same problem with a JS Lib I'm using where I want to send some of its objects to DWR, but it has alot of client side attributes for graphics/handlers. I haven't found a way around it. DWR has nothing on the client side to tell it to only send certain attributes of an object.
Randy ________________________________ From: Bruno Klava [mailto:bklava@...] Sent: Thu 4/17/2008 4:13 PM To: users@... Subject: Re: [dwr-user] Excluding properties when converting from JavaScript to Java objects > I am a bit confused. If b is not a part of Foo why are you setting it in > your JavaScript object? It's a gui element representing this object (the user can manipulate the data using the gui elements, and the structure is quite complex, so i need a reference from each element to its gui element). --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
|
|
|
|
|
|
RE: Excluding properties when converting from JavaScript to Java objectsI think it is basically the same situation. I agree it may not be DWR's job, but it would be nice if it was intelligent enough to know what to seralize to send to the server in cases like this. It is alot of code for me to rewrite everyobject I want to send to dwr if my api is say dojo (or build on dojo as is my case)...
"My feeling is that there is an easier way."
You're right and DWR handling it would be the easiest way from a developer's perspective instead of having to rebuild every object that has attributes you don't want to be sent. Again I'm not saying it should DWR's job, just playing devil's advocate with a hit of sympathy based on experience.
I'm glad you've been using DWR for so long, alot of us have and the community is growing.
Randy From: david@... [mailto:david@...] Sent: Thu 4/17/2008 4:37 PM To: users@... Subject: RE: [dwr-user] Excluding properties when converting from JavaScript to Java objects I can see this scenario but I think we are dealing with something else |
|
|
|
|
|
RE: Excluding properties when converting from JavaScript to Java objectsI don't know...since you're required to include a dwr generated js file
already it might be possible to have information in it that engine.js uses to serialize less...but some converter information might need to be added that's not there. Maybe I'll look at it after I get the JSON-RPC stuff done. Randy -----Original Message----- From: david@... [mailto:david@...] Sent: Thursday, April 17, 2008 5:12 PM To: users@... Subject: RE: [dwr-user] Excluding properties when converting from JavaScript to Java objects I definitely can see your point but I am thinking level of effort versus usage. It seems this is a pretty unique situation and the level of effort to implement it in DWR may be pretty high (not sure). Original Message: ----------------- From: Randy Jones randy_jones@... Date: Thu, 17 Apr 2008 14:04:55 -0700 To: users@..., users@... Subject: RE: [dwr-user] Excluding properties when converting from JavaScript to Java objects I think it is basically the same situation. I agree it may not be DWR's job, but it would be nice if it was intelligent enough to know what to seralize to send to the server in cases like this. It is alot of code for me to rewrite everyobject I want to send to dwr if my api is say dojo (or build on dojo as is my case)... "My feeling is that there is an easier way." You're right and DWR handling it would be the easiest way from a developer's perspective instead of having to rebuild every object that has attributes you don't want to be sent. Again I'm not saying it should DWR's job, just playing devil's advocate with a hit of sympathy based on experience. I'm glad you've been using DWR for so long, alot of us have and the community is growing. Randy ________________________________ From: david@... [mailto:david@...] Sent: Thu 4/17/2008 4:37 PM To: users@... Subject: RE: [dwr-user] Excluding properties when converting from JavaScript to Java objects I can see this scenario but I think we are dealing with something else here. I think there is a better way to approach it. Regardless, I think it is unreasonable to expect DWR to know what to send the server. I think the developer has to be responsible for what he sends to the server. If you want a skimmed down version of something create the skimmed down version and pass that to the server. Original Message: ----------------- From: Randy Jones randy_jones@... Date: Thu, 17 Apr 2008 13:19:05 -0700 To: users@... Subject: RE: [dwr-user] Excluding properties when converting from JavaScript to Java objects I've had the same problem with a JS Lib I'm using where I want to send some of its objects to DWR, but it has alot of client side attributes for graphics/handlers. I haven't found a way around it. DWR has nothing on the client side to tell it to only send certain attributes of an object. Randy ________________________________ From: Bruno Klava [mailto:bklava@...] Sent: Thu 4/17/2008 4:13 PM To: users@... Subject: Re: [dwr-user] Excluding properties when converting from JavaScript to Java objects > I am a bit confused. If b is not a part of Foo why are you setting it in > your JavaScript object? It's a gui element representing this object (the user can manipulate the data using the gui elements, and the structure is quite complex, so i need a reference from each element to its gui element). --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... -------------------------------------------------------------------- mail2web - Check your email from the web at http://link.mail2web.com/mail2web --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... -------------------------------------------------------------------- mail2web LIVE - Free email based on Microsoft(r) Exchange technology - http://link.mail2web.com/LIVE --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Excluding properties when converting from JavaScript to Java objectsMy final solution was to modify the dwr.engine._serializeObject
function, inside the loop over the elements, to skip the serialization of the undesired elements. Like you said, it would be very nice to improve this in the DWR code, avoiding the serialization of data that doesn't match the prototype and will never be used on the server side. Thanks for your help! Bruno On Thu, Apr 17, 2008 at 7:04 PM, Randy Jones <randy_jones@...> wrote: > I don't know...since you're required to include a dwr generated js file > already it might be possible to have information in it that engine.js > uses to serialize less...but some converter information might need to be > added that's not there. Maybe I'll look at it after I get the JSON-RPC > stuff done. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
RE: Excluding properties when converting from JavaScript to Java objectsHi Bruno,
It sound reasonable that DWR should prevent that. Could you create a bug report at http://getahead.org/bugs ? Best regards Mike Wilson > -----Original Message----- > From: Bruno Klava [mailto:bklava@...] > Sent: den 17 april 2008 21:33 > To: DWR 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@... > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free Forum Powered by Nabble | Forum Help |