I have a similar question like [this][1], but I couldn’t find any examples, at all, for form validation with revert option.
Suppose we have a form with **Save** and **Cancel** operations.
I want on `save()` method
the binder actually to update the bean, but on `cancel()` method, it should do nothing with the bean and leave it as it was, with previous value.
Here are my main questions:
- How the binder should be initialized, to achieve such functionality ?
- How to retrieve the updated bean on save method ?
I tried something like this, but the bean is always null on save operation
private void initBinder() {
binder.writeBeanAsDraft(myBean);
binder.forField(inputField)
....
}
private void save() {
binder.writeBeanIfValid(myBean);
binder.readBean(myBean); // retrieve the bean, to save it
...
// save the bean to database
}
private void cancel() {
binder.getBean(); // retrieve unchanged bean
// resets the old values
inputField.setValue(binder.getBean().getValue());
}
Any help will great, thanks in advance!