使用 RequestFactoryEditorDriver 动态更新
我有一个文本字段,我想在用户输入内容时定期保存它。我想将其连接到我现有的 RequestFactoryEditorDriver 框架中,但我想不出办法来做到这一点。问题是我必须等待所有 driver.flush().fire()
调用返回才能再次调用 edit()
,所以在同时数据将不可编辑。
到目前为止,我最好的解决方案是在代理之上创建一个完整的层。它会等到它即将保存,然后编辑代理,复制更改,并保留代理,但那时我失去了编辑器框架的大部分好处。有人有更好的想法吗?
I have a text field that I want to save periodically as users type in it. I'd like to hook it into my existing RequestFactoryEditorDriver framework, but I can't think of a way to do so. The trouble is that I'd have to wait for all of my driver.flush().fire()
calls to return before calling edit()
again, so in the meantime the data would not be editable.
My best solution so far is to create an entire layer above the proxy. It would wait until it was just about to save, and then edit the proxy, copy in the changes, and persist the proxy, but at that point I'm losing most of the benefit of the Editor framework. Does anyone have any better ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信另一件事会起作用,并且可能不会比雷的答案涉及更多的工作(实际上可能更少):不要编辑要保存的对象,而是编辑它的副本(使用
RequestContext.create( 创建) )
),在编辑之前制作一个副本,然后在触发之前刷新并复制回您的 bean(在另一个RequestContext
中)。然而,由于与服务器的异步通信,这假定不会发生并发编辑(用户可以继续编辑,如果其他人同时编辑同一对象,您必须检测并解决“冲突”) 。
要制作副本,请使用 AutoBeanUtils.getAutoBean 从 RF 代理中获取 bean,然后使用 AutoBeanVisitor 访问所有属性并将其值复制到另一个代理/autobean 中。
Another thing that I believe would work, and probably wouldn't involve much more work (probably less actually) than Ray's answer: do not edit the object you want to save but a copy of it (created with
RequestContext.create()
), make a copy before you edit, and then flush and copy back to your bean (in anotherRequestContext
) before firing.This however presumes there won't be concurrent edits, because of the asynchronous communication with the server (the user can continue editing, and you'd have to detect and resolve "conflicts" if someone else edited the same object at the same time).
To make a copy, use
AutoBeanUtils.getAutoBean
to get the bean out of the RF proxy, then anAutoBeanVisitor
to visit all properties and copy their values into another proxy/autobean.我敢打赌,在较低级别解决这个问题不会太难。例如,在 RequestFactory 本身周围放置一个包装器,使所有 void 返回同步触发它们的回调,假设 99% 的情况下它们确实会成功。
I bet it wouldn't be too hard to tackle this at a lower level. E.g., put a wrapper around the RequestFactory itself that makes all void returns fire their call back synchronously, presuming that 99% of the time they really will succeed.