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.flus开发者_StackOverflow社区h().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?
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 another RequestContext
) 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 an AutoBeanVisitor
to visit all properties and copy their values into another proxy/autobean.
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.
精彩评论