GWT RequestFactory 和多个请求
有没有办法使用 RequestFactory 在单个请求中创建两个实体?我尝试过:
EmployeeRequest request = requestFactory.employeeRequest();
EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
newEmployee.setName("Joe!");
Request<Void> createReq = request.persist().using(newEmployee);
createReq.fire();
EmployeeProxy newEmployee2 = request.create(EmployeeProxy.class);
newEmployee2.setName("Sam!");
Request<Void> createReq2 = request.persist().using(newEmployee2);
createReq2.fire();
但我收到一个错误,表明请求已在进行中。当我发出两个单独的 EmployeeRequests 时:
EmployeeRequest request = requestFactory.employeeRequest();
EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
newEmployee.setName("Joe!");
Request<Void> createReq = request.persist().using(newEmployee);
createReq.fire();
EmployeeRequest request2 = requestFactory.employeeRequest();
EmployeeProxy newEmployee2 = request2.create(EmployeeProxy.class);
newEmployee2.setName("Sam!");
Request<Void> createReq2 = request2.persist().using(newEmployee2);
createReq2.fire();
然后从浏览器发出两个单独的请求。我希望 RequestFactory 中的某些东西可以合并多个请求 - 我必须一次创建数百个实体,而且我不想发出数百个请求!
Is there a way to use RequestFactory to create two entities in a single request? I tried:
EmployeeRequest request = requestFactory.employeeRequest();
EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
newEmployee.setName("Joe!");
Request<Void> createReq = request.persist().using(newEmployee);
createReq.fire();
EmployeeProxy newEmployee2 = request.create(EmployeeProxy.class);
newEmployee2.setName("Sam!");
Request<Void> createReq2 = request.persist().using(newEmployee2);
createReq2.fire();
But I get an error that a request is already in progress. When I made two separate EmployeeRequests:
EmployeeRequest request = requestFactory.employeeRequest();
EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
newEmployee.setName("Joe!");
Request<Void> createReq = request.persist().using(newEmployee);
createReq.fire();
EmployeeRequest request2 = requestFactory.employeeRequest();
EmployeeProxy newEmployee2 = request2.create(EmployeeProxy.class);
newEmployee2.setName("Sam!");
Request<Void> createReq2 = request2.persist().using(newEmployee2);
createReq2.fire();
Then two separate requests are made from the browser. I'm hoping that something in the RequestFactory can merge multiple requests - I have to create hundreds of entities at a time, and I don't want to make hundreds of requests!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的。在第一个示例中,只需删除最后一行
When you call
createReq2.fire()
,然后 GWT 在一个请求中同时发送 newEmployee 和 newEmployee2 (因为它们都保留在您的上下文中) EmployeeRequest“请求
”)。我个人觉得语义有点奇怪,但这只是我的意见。赖利的附录:
以下语法是等效的并且更直观:
Yes, it's possible. In your first example, just remove the line
When you call
createReq2.fire()
at the end, then GWT sends both newEmployee and newEmployee2 in one single request (because they were both persisted in the context of your EmployeeRequest "request
"). I personally find the semantics a bit strange, but that's just my opinion.Addendum by Riley:
The following syntax is equivalent and is much more intuitive: