ListEditor adding immutable object from another RequestFactory request.

57 views
Skip to first unread message

salk31

unread,
Jan 4, 2013, 11:40:59 AM1/4/13
to google-we...@googlegroups.com
I'm not sure of the contract with a ListEditor. If I fetch an object using a different RequestContext is it my responsibility to make it editable in the editors RequestContext before adding to the list?

The problem I'm having is that if I don't then when adding to the ListEditor the method AbstractEditorDelegate$Chain<R,S>.attach(R, S) line: 83 will grab a mutable copy so the item editor will have a different instance to the one in the list... This seems bad.

So should I do listEditor.getList().add(requestContext.edit(newThing))  ?  

Cheers

Sam



 

Thomas Broyer

unread,
Jan 5, 2013, 6:29:45 AM1/5/13
to google-we...@googlegroups.com

On Friday, January 4, 2013 5:40:59 PM UTC+1, salk31 wrote:
I'm not sure of the contract with a ListEditor. If I fetch an object using a different RequestContext is it my responsibility to make it editable in the editors RequestContext before adding to the list?

The problem I'm having is that if I don't then when adding to the ListEditor the method AbstractEditorDelegate$Chain<R,S>.attach(R, S) line: 83 will grab a mutable copy so the item editor will have a different instance to the one in the list... This seems bad.

IIRC, if you pass an immutable proxy to the RequestFactoryEditorDriver, the ListEditor will be given a list of immutable proxies, and each "item editor" will then be given a mutable copy.

So should I do listEditor.getList().add(requestContext.edit(newThing))  ?

I always prefer explicitly edit()ing my proxies rather than let this responsibility to the editor driver, so I'd rather do it that way, but I don't think this is a must-do. 

salk31

unread,
Jan 5, 2013, 7:27:03 AM1/5/13
to google-we...@googlegroups.com
Thanks Thomas,

Explicit edit()ing does seem good as then the developer is aware that there will be two versions of the "same" object. What was catching me out is that the mutable copy is not equal() to its original, so remove from the list didn't work if I used the wrong reference. My only niggle with this is that the Editor/RequestFactory framework sometimes does this for you so not a nice simple "always pass editable proxies for the Editor framework to use"...

This seems quite a nasty gotcha for ListEditor with RequestFactory? Presumably the complication is that ListEditor should not be coupled to RequestFactory usage.

Do you think it would be worth me raising a ticket for some javadoc comments at least? ListEditor have something like "NB If using with RequestFactory then item Editors may be passed references to mutable copies of items added to the List...."

btw Have I done something wrong trying to get this tiny patch through http://www.gwt-code-reviews.appspot.com/1636803/  ? I love GWT so it would be nice to help even if it is just fixing typos in the Javadoc.

Sam
Reply all
Reply to author
Forward
0 new messages