1

我将 GWT 2.5rc1 与 RequestFactory 和 Editor 框架一起使用。当我保存具有关联模型的实体时,服务器Locator会在保存之前重新加载关联模型。因此,客户端中的任何更改都会被覆盖。例如:

@ProxyFor(value=Foo.class, locator=FooLocator.class)
public interface FooProxy extends EntityProxy {
  void setBar(BarProxy bar);
  BarProxy getBar();

}

@ProxyFor(value=Bar.class, locator=BarLocator.class)
public interface BarProxy interface EntityProxy {
  ...
}

// The save method implemented in an Activity.
// Invoked when the editor's save button is clicked.
public void onSave() {
  // driver is a RequestFactoryEditorDriver
  FooRequest request = (FooRequest) driver.flush();
  request.save(entity).fire(myReceiver);
}

// The service on the server that saves the two entities.
public class FooService {

  public Foo save(Foo foo) {
    barDao.save(foo.getBar()); // Bar has been reloaded via the BarLocator and all changes lost
    fooDao.save(foo);
    return foo;
  }
}

在服务器上,BarLocator.find(...)调用该方法重新加载 Bar 实例并覆盖对传入 Bar 实例所做的任何更改。

示例日志输出:

FooLocator loading Foo
setBar called
BarLocator loading Bar
save called

最后三行都是指从数据库加载的 Bar;我从未在我的任何定位器或服务代码中看到更改后的栏。

4

0 回答 0