RequestFactoryEditorDriver.flush() doesn't change edited object

167 views
Skip to first unread message

Jens

unread,
Oct 6, 2011, 9:19:47 AM10/6/11
to google-we...@googlegroups.com
Hi,

I am just playing around with the Editor Framework in combination with RequestFactoryEditorDriver and currently calling RFED.flush() does not update the edited object and I can not see why.

The app is pretty simple and the workflow is:
1.) Create view and initialize RFED
2.) Create a Person on the server datastore (simple hash map and UUID as id)
3.) Fetch the created person from server using the .stableId()
4.) start editing the fetched person
5.) at some point (currently on key up events while editing the persons name) do RFED.flush()
6.) PersonProxy does not contain updated name.


Client Side code:

@Override
public void onModuleLoad() {

//init view
view = new PersonViewImpl();
view.setDelegate(this);
RootPanel.get().add(view);

//init RequestFactory and RFED
requestFactory = GWT.create(AppRequestFactory.class);
requestFactory.initialize(new SimpleEventBus());
driver = view.createDriver();
driver.initialize(requestFactory, view);

//create person on server datastore (hash map)
PersonRequest createRequest = requestFactory.personRequest();
final PersonProxy p = createRequest.create(PersonProxy.class);
createRequest.persist(p);
createRequest.fire(new Receiver<Void>() {
@Override
public void onSuccess(final Void result) {
//fetch created person from server
Request<PersonProxy> findRequest =
(Request<PersonProxy>) requestFactory.find(p.stableId()).with(driver.getPaths());
findRequest.fire(new Receiver<PersonProxy>() {
@Override
public void onSuccess(final PersonProxy foundPerson) {
//start editing fetched person
PersonRequest editRequest = requestFactory.personRequest();
//editPerson = editRequest.create(PersonProxy.class);
editPerson = foundPerson;
editRequest.persist(editPerson);
driver.edit(editPerson, editRequest);
}
});
}
});
}

@Override
public void onDataChanged() {
                //try to autosave the changed data
if(driver != null) {
driver.flush();
System.out.println("edited: " + editPerson.getName() + ", " + editPerson.getUuid());
                        //... clone editPerson and save the clone with a separate request context....
                }
         }

When I am not editing the fetched person but editing a newly created one (see editPerson = editRequest.create(PersonProxy.class);), it works like expected and editPerson contains the updated name. But this will also create new persons on server side once I will save changes of the person proxy.

What am I missing? I think it shouldn't be much of a difference if the proxy is newly created or fetched from server.

Also you may notice that I do not use the RequestContext returned by driver.flush() because I clone the proxy anyways and save it in background in a separate RequestContext (auto save functionality and that way I am able to continuously edit the proxy while saving it). So in general a SimpleBeanEditorDriver would be enough for editing but I would like to use the getPaths() method of RFED when fetching data from server. Is there an easy way to calculate paths for a SimpleBeanEditorDriver? 

Thanks in advance.
-- J.

Thomas Broyer

unread,
Oct 6, 2011, 10:12:41 AM10/6/11
to google-we...@googlegroups.com
Your 'editPerson' variable points to the immutable version received by your first request. When you pass it to the RFED, it'll RequestContext#edit() it, and modify the returned mutable version.

You'd like to "editPerson = editRequest.edit(foundPerson)" first (calling RequestContext#edit() on a mutable object returns that object, so it's safe to pass editPerson to the RFED; actually you could even pass the foundPerson, as calling edit() in the same RequestContext on the same immutable proxy will always return the same mutable proxy).

Jens

unread,
Oct 6, 2011, 11:24:24 AM10/6/11
to google-we...@googlegroups.com
Ahhh I see...now it works. Thanks for that.

Using SimpleBeanEditorDriver you get the edited bean when calling .flush(). Wouldn't it be handy if RFED returns the mutable instance when calling RFED.edit()? RFED.flush() returns the request context so RFED.edit() would be a good choice if you want to access the mutable object. Would be a bit easier.

But anyways I have also found the PathCollector EditorVisitor so I think I could switch to SimpleBeanEditorDriver + getPaths() via visitor.

-- J.
Reply all
Reply to author
Forward
0 new messages