gwt与RequestFactory,处理客户端和RequestFactoryEditorDriver服务器端异常
问题描述:
我使用RequestFactory与客户端的服务器和RequestFactoryEditorDriver进行通信。所以编辑工作流程就像这样。编辑创建新的代理:gwt与RequestFactory,处理客户端和RequestFactoryEditorDriver服务器端异常
RequestContext reqCtx = clientFactory.getRequestFactory().Request();
UserAndAccountProxy userAndAccountProxy = reqCtx.create(UserAndAccountProxy.class);
reqCtx.saveAndReturnProfileAndAccount(userAndAccountProxy).to(
new Receiver<UserAndAccountProxy>() {
@Override
public void onSuccess(UserAndAccountProxy response) {
...
}
@Override
public void onFailure(ServerFailure error) {
...
}}
而且保存按钮点击处理:
RequestContext reqCtx = view.getEditorDriver().flush();
reqCtx.fire();
在服务器端saveAndReturnProfileAndAccount方法可以坚持,我可以在onFailure处方法处理抛出异常。之后,如果我使用新的请求上下文创建新代理并将其传递给我的编辑器,则所有字段都将空白。 那么什么是正确的方式来执行请求,如果出现错误使用数据,用户已经填写或可能我犯了我的编辑worklow错误?
答
所以,我认为,我找到了解决方案。我做了修改功能,创建的RequestContext:
private void edit(MyProxy proxy) {
RequestContext reqCtx = clientFactory.getRequestFactory().Request();
if (proxy == null) {
// create proxy first time
proxy = reqCtx.create(UserAndAccountProxy.class);
} else {
// create immutable copy
proxy = reqCtx.edit(proxy);
}
final UserAndAccountProxy tmp = proxy;
reqCtx.saveAndReturnMyProxy(proxy).to(new Receiver<MyProxy>() {
@Override
public void onFailure(ServerFailure error) {
eventBus.showErrorInformation(error.getMessage());
//recursive call with already filled proxy
edit(tmp);
}
@Override
public void onSuccess(UserAndAccountProxy response) {
eventBus.showInformation("It`s ok!");
eventBus.goToMainPage(null);
}
});
// start editing with editor
getView().onEdit(tmp, reqCtx);
}
当我们开始编辑代理功能,编辑需要蜜蜂调用空参数和新的清洁代理将被创建。之后,我们开始用编辑器编辑它。在保存按钮上单击我们执行请求到服务器。如果它以成功结束 - 我们打开另一个页面。如果请求以错误结束,我们创建新的不可变副本ant将其推送给编辑器。
我尝试使用客户端中的相同字段创建类,并在编辑器中进行编辑。在保存处理程序创建代理类和复制字段到它并执行请求,但是,我认为,这不是很好的解决方案。 – user1779661