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?
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.getAutoBeanto get the bean out of the RF proxy, then anAutoBeanVisitorto visit all properties and copy their values into another proxy/autobean.