GWT请求工厂+;编辑器框架重新加载关联实体
我将GWT2.5rc1与RequestFactory和编辑器框架一起使用。保存具有关联模型的实体时,服务器的GWT请求工厂+;编辑器框架重新加载关联实体,gwt,gwt2,requestfactory,gwt-editors,Gwt,Gwt2,Requestfactory,Gwt Editors,我将GWT2.5rc1与RequestFactory和编辑器框架一起使用。保存具有关联模型的实体时,服务器的定位器将在保存之前重新加载关联模型。因此,客户机中的任何更改都是重写的。例如: @ProxyFor(value=Foo.class, locator=FooLocator.class) public interface FooProxy extends EntityProxy { void setBar(BarProxy bar); BarProxy getBar(); } @
定位器将在保存之前重新加载关联模型。因此,客户机中的任何更改都是重写的。例如:
@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
最后三行都是指从DB加载的条;我从来没有在我的任何定位器或服务代码中看到更改的条。您在Foo
上有setBar
吗?我一直在玩这个。Foo是否应该返回一个完全混合的Foo?换句话说,酒吧应该存在吗?当前的fooolocator.find实现返回带条集的Foo。问题出在save()上,傻瓜操作器调用setBar()。当您将两个对象(foo和bar)发送到服务器时,它将找到它们(或为值代理创建),调用属性设置器(包括setBar
),然后只调用服务方法;因此,如果getter/setter是字段的简单访问器,那么foo.getBar()
应该从Locator
加载的Bar
中获取您的属性。那么我是否无法保存对象图?我想说的是,您的代码应该可以工作。但它可能失败的原因有很多(不使用视图模式中的开放会话,做的不仅仅是在setters中分配一个字段,等等)