Andy King
Andy King

Reputation: 1662

GWT EditorDriver Proxy Object Modification

This is an edited version of a question that I had previously asked (and that tbroyer answered) about why the isDirty() method didn't return true after attempting to modify the Editor version of an entity. I think that my understanding of the RequestFactory/EditorDriver handling of entities is the issue, and that the isDirty() question was a red herring. I've left my original question at the end of this question, but my new question is:

How can the entity (proxy) that is being edited by an EditorDriver be modified in code? Obviously values will be changed as a result of changes in the user interface; but I don't know how to change values 'behind the scenes'. My understanding is that the call to EditorDriver.edit() will create a copy of the proxy object, and that subsequently any changes to that copy will be applied to the original object using EditorDriver.flush(). But EditorDriver.edit() does not return a reference to the object that is being edited (unlike RequestContext.edit(), which does return a reference to the object being edited).

The original (ill-informed) question:

I don't understand why the EditorDriver.isDirty() method is not returning true in the following situation (the following onOrgSelectedEvent() method is invoked when a new Org has been selected from a listbox):

private IOrgProxy _org;
...
/**
 * Loads the currently selected Org into the editor. 
 */
@Override
public void onOrgSelectedEvent(final OrgSelectedEvent orgSelectedEvent) {
  IOrgProxy org = _clientFactory.getCache().getOrgCache().getOrg(orgSelectedEvent.getOrgId());
  _orgRequestContext = _clientFactory.getRequestFactory().newOrgRequestContext();
  _org = _orgRequestContext.edit(org);
  _orgEditorDriver.edit(_org, _orgRequestContext);
  _org.setName(_org.getName() + " (edit)");
  if (_orgEditorDriver.isDirty()) {
    _org.setName(org.getName());
  }
}

When I put breakpoints on the setName() calls I see that the first call changes the name in the editable Org object, but the second setName() call is never reached (i.e., _orgEditorDriver.isDirty() returns false).

Just as a side question, it seems strange to me that the EditorDriver.edit() method doesn't return the editable proxy object, and that I have to call RequestContext.edit(), but that's a very minor issue.

Upvotes: 0

Views: 357

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

Why would isDirty be true just after edit? Clearly the user hasn't be given the time to do any change.

isDirty compares the current value of the subeditors to their original value, it doesn't care whether the object changed: if you lend the object to the editor, you implicitly gives it control over the edited object (for the edited properties).

Upvotes: 3

Related Questions