Is there a way to get the proxy that editor is editing?
The normal workflow would be:
public class Class implments Editor<Proxy>{
@Path("")
@UiField AntoherClass subeditor;
void someMethod(){
Proxy proxy = request.create(Proxy.class);
driver.save(proxy);
driver.edit(proxy,request);
}
}
Now if i got a subeditor of the same proxy
public class AntoherClass implements Editor<Proxy>{
someMethod(){
// method to get the editing proxy ?
}
}
Yes i know i can just set the proxy to the Child editor with setProxy() after its creation, but i want to know if there is something like HasRequestContext but for the edited proxy.
This usefull when you use for example ListEditor in non UI objects.
Thank you.
This is the only solution I found. It involves calling the context edit before you call the driver edit. Then you have the proxy to manipulate later.
In your child editor class, you can just implement another interface TakesValue, you can get the editing proxy in the setValue method.
ValueAwareEditor works too, but has all those extra method you don't really need.
Two ways you can get a reference to the object that a given editor is working on. First, some simple data and a simple editor:
First: Instead of implementing
Editor
, we can pick another interface that also extends Editor, but allows sub-editors (LeafValueEditor
does not allow sub-editors). Lets tryValueAwareEditor
:This requires that you implement the various methods as in the example above, but the main one you are interested in will be
setValue
. You do not need to invoke these yourself, they will be called by the driver and its delegates. Theflush
method is also good to use if you plan to make changes to the object - making those changes before flush will mean that you are modifying the object outside of the expected driver lifecycle - not the end of the world, but might surprise you later.Second: Use a
SimpleEditor
sub-editor:Using this, you can call
self.getValue()
to read out what the current value is.Edit: Looking at the
AnotherEditor
you've implemented, it looks like you are starting to make something like the GWT classSimpleEditor
, though you might want other sub-editors as well:This sub-editor could implement
ValueAwareEditor<Proxy>
instead ofEditor<Proxy>
, and be guaranteed that itssetValue
method would be called with the Proxy instance when editing starts.