Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Form.commit() - request any updates to widget components
Will a Form.commit() somehow query the GWT widgets to get their final data values (such as when immediate is false)? Just trying to figure out if I have a custom widget, how to ensure when a save button on my form calls Form.commit(), will it always have the latest data (I know I have a widget that sometimes seems to 'blur' after the button has already sent immediate).
And conversely, if Form.discard() is called, will it then send the original data value back to all my custom widgets to reset back to whatever value they had before?
The Form.commit() does not "query the GWT widgets", as GWT widgets are objects on the client-side. The GWT widgets serialize their state to the server-side components and Form.commit() applies to those. The commit() is purely a server-side functionality (defined in the Buffered interface) that writes the internally stored value of a field to its bound data source (when setWriteThrough() is false - if its true calling commit() explicitly is irrelevant).
I understood that you have made a custom widget (a client-side GWT widget + the server-side counterpart). You just have to serialize the client-side state to the server-side (call the updateVariable() to send the variable states to server and, on the server-side, handle the component state changes in changeVariables()) and store the value with setValue().
The buffering is implemented in AbstractField so you don't have to do anything else in your own component but use the setValue() to store the data in changeVariables(). Oh, this assumes that your server-side component inherits AbstractField, of course. Otherwise you'd have to implement the Buffered interface yourself.
If writeThrough is false (you are using write buffering), immediateness is irrelevant with the form's OK button, as Button events are always sent immediately from the client to server and when that occurs, any pending variable changes in any non-immediate form fields are also sent. So the other form fields don't need to be immediate (though their immediateness may be necessary for server-side validation, etc).
And yes, when Form.discard() is called, the server-side value of the fields is read from the data source, written to the server-side buffer, and automatically sent to the widgets (custom or not). The discard() requires that you have implemented the server-to-client serialization (paintContent() on the server-side and updateFromUIDL() on the client-side).
I hope this didn't get too complex.
Thanks for the details. I think I understood. :)
It makes sense. I was concerned because the CKEditor widget (subclass of TextField) was having issues with blur events sometimes being processed after the button's click event. We now have a way to remove the built in 100ms delay of CKEditor for the blur event, so it seems to be more reliable (when the button is clicked, it will have the latest updates to the editor). Barring that, it was only reliable if the edit was in 'immediate' mode, but that seemed bandwidth wasteful to send the HTML editors contents each time it lost focus.
Thanks for the info on discard() too. That should work great. I'm just now going to integrated CKEditor into a Form, so I'll see if anything else pops out.