ListEditor doesn't detect changes in sub-editors if using RequestFactory driver

372 views
Skip to first unread message

Ignacio Baca Moreno-Torres

unread,
Jul 4, 2011, 4:46:06 PM7/4/11
to google-we...@googlegroups.com
When I run the code, shown bellow, and I modify profile.name and equipment[1].type in the UI, I get this output log in GWT.

PreFlush {profile=name, equip=hat, dirty=true}
PostFlush {profile=other name, equip=hat, dirty=true}

So "equipment.name" is never updated in the proxy instance. Also I launched the following tests.
1. If I do not modify anything, dirty is always false.
2. If I modify just equipment name, dirty es true, but not updated.
3. I add new element to the list,code not here, and the new element is added correctly and persisted in the server.

I do one more test. Change RequestFactoryEditorDriver to SimpleBeanEditorDriver. And the log show that the proxy,now simple JavaBean object, is updated correctly. 

PreFlush {profile=name, equip=hat, dirty=true}
PostFlush {profile=other name, equip=other type, dirty=true}

Why ListEditor doesn't update the proxy instance when using RequestFactoryEditorDriver? Thanks.

RequestFactoryEditorDriver Version
public class ProfileEditor extends Composite implements Editor<ProfileProxy> {
 
  /** Class capable of creating and destroying instances of EquipmentEditor */
  private class EquipmentEditorSource extends EditorSource<EquipmentEditor> {
 
    public EquipmentEditor create(int index) {
      EquipmentEditor editor = new EquipmentEditor();
      equipmentContainer.insert(editor, index);
      return editor;
    }
 
    public void dispose(EquipmentEditor subEditor) {
      subEditor.removeFromParent();
    }
 
    public void setIndex(EquipmentEditor editor, int index) {
      equipmentContainer.insert(editor, index);
    }
  }
 
  /* UiBinder */
  static ThisUiBinder uiBinder = GWT.create(ThisUiBinder.class);
  interface ThisUiBinder extends UiBinder<Widget, ProfileEditor> { }
  
  /* Editor driver */
  interface Driver extends RequestFactoryEditorDriver<ProfileProxy, ProfileEditor> { }
  final Driver driver = GWT.create(Driver.class);
 
  @UiField ValueBoxEditorDecorator<String> name;
  @UiField FlowPanel equipmentContainer;
  
  ListEditor<EquipmentProxy, EquipmentEditor> equipmentListEditor
    = ListEditor.of(new EquipmentEditorSource());
 
  AppRequestFactory requestFactory;
  ProfileProxy proxyBeingEdited;
  
  public ProfileEditor(ClientFactory clientFactory) {
    requestFactory = clientFactory.getRequestFactory();
    initWidget(uiBinder.createAndBindUi(this));
    driver.initialize(this);
    fetchProxy(); // through requestFactory
  }
  
  void fetchProxy() {
    requestFactory.profileRequest().getCurrentUserProfile()
      .with(driver.getPaths())
      .to(new Receiver<ProfileProxy>() {
        public void onSuccess(ProfileProxy currentUser) { 
          startEdit(currentUser);
        }
      }).fire();
  }
  
  private void startEdit(ProfileProxy proxy) {
    ProfileRequest editContext = requestFactory.profileRequest();
    // Not necesary, but usefull to see if something happen!
    proxyBeingEdited = editContext.edit(proxy);
    driver.edit(proxyBeingEdited, editContext);
    //           Changes saved here --^
    editContext.persist().using(proxyBeingEdited);
  }
  
  @UiHandler("save")
  void onSave(ClickEvent event) {
    ProfileProxy o = proxyBeingEdited;
    GWT.log("PreFlush {profile=" + o.getName() + ", equip="
        + o.getEquipmentList().get(0).getType() + ", dirty="
        + driver.isDirty() + "}"); // PRELOG!!
 
    RequestContext editedContext = driver.flush();
 
    GWT.log("PostFlush {profile=" + o.getName() + ", equip="
        + o.getEquipmentList().get(0).getType() + ", dirty="
        + driver.isDirty() + "}"); // POSTLOG!!
 
    // Send the request
    editedContext.fire(new Receiver<Void>() {
      public void onSuccess(Void response) {
        startEdit(proxyBeingEdited); // Critical if you want re-save!
      }
    });
  }
 
}
public class EquipmentEditor extends Composite implements Editor<EquipmentProxy> {
 
  /* UiBinder */
  private static ThisUiBinder uiBinder = GWT.create(ThisUiBinder.class);
  interface ThisUiBinder extends UiBinder<Widget, EquipmentEditor> { }
  
  @UiField TextBox type;
  
  public EquipmentEditor() { initWidget(uiBinder.createAndBindUi(this)); }
 
}


SimpleBeanEditorDriver Version
public class ProfileEditor extends Composite implements Editor<ProfileProxy> {
 
  /** Class capable of creating and destroying instances of EquipmentEditor */
  private class EquipmentEditorSource extends EditorSource<EquipmentEditor> {...
  
  /* UiBinder */
  static ThisUiBinder uiBinder = GWT.create(ThisUiBinder.class);
  interface ThisUiBinder extends UiBinder<Widget, ProfileEditor> { }
  
  /* Editor driver */
  interface Driver extends SimpleBeanEditorDriver<ProfileProxy, ProfileEditor> { }
  final Driver driver = GWT.create(Driver.class);
 
  @UiField ValueBoxEditorDecorator<String> name;
  @UiField FlowPanel equipmentContainer;
  
  ListEditor<EquipmentProxy, EquipmentEditor> equipmentListEditor
    = ListEditor.of(new EquipmentEditorSource());
 
  AppRequestFactory requestFactory;
  ProfileProxy proxyBeingEdited;
  
  public ProfileEditor(ClientFactory clientFactory) {
    requestFactory = clientFactory.getRequestFactory();
    initWidget(uiBinder.createAndBindUi(this));
    driver.initialize(this);
    startEdit(createProxy());
  }
  
  private void startEdit(ProfileProxy proxy) {
    proxyBeingEdited = proxy;
    driver.edit(proxyBeingEdited);
  }
  
  @UiHandler("save")
  void onSave(ClickEvent event) {
    ProfileProxy o = proxyBeingEdited;
    GWT.log("PreFlush {profile=" + o.getName() + ", equip="
        + o.getEquipmentList().get(0).getType() + ", dirty="
        + driver.isDirty() + "}"); // PRELOG!!
 
    driver.flush();
 
    GWT.log("PostFlush {profile=" + o.getName() + ", equip="
        + o.getEquipmentList().get(0).getType() + ", dirty="
        + driver.isDirty() + "}"); // POSTLOG!!
    
  }
ProfileProxy create(){
    ProfileProxy object = new ProfileProxy(){
      String profileName; List<EquipmentProxy> eList;
      public EntityProxyId<?> stableId() { return null; }
      public String getUserId() { return null; }
      public String getNick() { return null; }
      public void setNick(String nick) { }
      public String getName() { return profileName; }
      public void setName(String name) { profileName = name; }
      public List<EquipmentProxy> getEquipmentList() { return eList; }
      public void setEquipmentList(List<EquipmentProxy> equipmentList) { eList = equipmentList; }
 
    };
    object.setName("Bean Name");
 
    EquipmentProxy equipment = new EquipmentProxy() {
      String eType;
      public EntityProxyId<?> stableId() { return null; }
      public void setYear(Integer year) { }
      public void setType(String type) { eType = type; }
      public void setSize(Integer size) { }
      public void setModel(String model) { }
      public void setComment(String comment) { }
      public void setBrand(String brand) { }
      public Integer getYear() { return null; }
      public String getType() { return eType; }
      public Integer getSize() { return null; }
      public String getModel() {return null; }
      public Long getId() { return null; }
      public Date getDueDate() { return null; }
      public String getDescription() { return null; }
      public String getComment() { return null; }
      public String getBrand() { return null; }
    };
    equipment.setType("Bean Type");
    object.setEquipmentList(new ArrayList<EquipmentProxy>(Arrays.asList(equipment)));
 
    return object;
  }
}


Thomas Broyer

unread,
Jul 4, 2011, 5:53:14 PM7/4/11
to google-we...@googlegroups.com
See http://code.google.com/p/google-web-toolkit/issues/detail?id=6081
This is a regression in 2.3. Hopefully it'll be fixed in 2.4 (honestly, I don't mind, I don't run official releases)

Ignacio Baca Moreno-Torres

unread,
Jul 4, 2011, 6:28:54 PM7/4/11
to google-we...@googlegroups.com
Thanks! Your patch look perfect, but GWT developers won't seem to apply it in the next release. I'm currently using GWT 2.4.0beta. I hope this will change in final release.

Thomas Broyer

unread,
Jul 4, 2011, 6:34:56 PM7/4/11
to google-we...@googlegroups.com
Feel free to "ping" in the issue; but it might be better to wait a few days, as BobV is "on vacation the early part of [this] week and will be studiously avoiding the computer"
Reply all
Reply to author
Forward
0 new messages