On Tuesday, September 9, 2014 2:06:59 PM UTC+2, Gordan Krešić wrote: > > In some of my editors, I'm implementing ValueAwareEditor<P> and using > provided proxy value in setValue to obtain editor-specific data (most > simple example would be to get suggestions for some sub-editors). Problem > is that proxy instance that I was given in setValue is already edited in > driver's RequestContext, so I'm unable to use it as parameter in another > context (for obtaining suggestions). Error is well known > "IllegalArgumentException: Attempting to edit an EntityProxy previously > edited by another RequestContext". > > My current workaround is to first obtain fresh instance (via > RequestContext.find(EntityProxyId<P>) and then use that (frozen) instance > for performing my initial request (e.g. MyRequest.getSuggestions(P)). > Drawback is that I have one unnecessary round-trip to the server. > > Another solution wound be to refactor getSuggestions method to accept only > id and rebuild full object on server side, but that seems to me as working > around RequestFactory instead of using its provided services. >
"Sending the proxy" will "rebuild full object on server side" anyway, so it's more a matter of taste (plus, whether you're OK returning suggestions for an object that's not in its "persisted" state: you could create a context, edit the object, change a few properties then call getSuggestions and fire, and the suggestions would be based on a modified entity, that won't be persisted). Sending only the ID allows you to use an optimized request to load the object from database (but might lead to loading it twice if calling getSuggestions in the same context as one where such a proxy is edit()ed). I would "optimize for the common case" and only pass the ID as an argument. > > Least feasible solution is to propagate frozen proxy instance from top > level editor all the way down editor hierarchy, but that leads to spaghetti > code. > > I know that RequestContext holds original (non-edit()ed, frozen) instance > for every EntityProxy (for calculating diffs that it needs to send to > server) - is there any way to get that original proxy from edited()-ed > instance? > Using AutoBeanUtils you can get the underlying AutoBean, then use getTag to get the parent AutoBean (use com.google.web.bindery.shared.impl.Constants.PARENT_OBJECT as the key), and finally call as() to view it as an EntityProxy. Any other suggestions? You could pass a ValueProxy as argument to your getSuggestions, and copy relevant properties from the EntityProxy. That way you don't need to load the object from the database on the server side, but you send all the data in the request, rather than just the entity ID. On the other hand, as I said above, only passing the ID as an argument, you can optimize your database query. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-web-toolkit. For more options, visit https://groups.google.com/d/optout.
