-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:Improve Binder change detection #19488
Conversation
|
protected void handleFieldValueChange(Binding<BEAN, ?> binding) { | ||
changedBindings.add(binding); | ||
|
||
protected void handleFieldValueChange(Binding<BEAN, ?> binding, ValueChangeEvent<?> event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid changing this method signature since it would be a breaking change and require waiting for the next major. Instead, one option could be to deprecate the current one, and if that is used, just skip the new change detection logic and function as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the current handleFieldValueChange
back as deprecated
* @return true if the field value is reverted | ||
*/ | ||
protected boolean isRevertedToInitialValue(Binding<BEAN, ?> binding, Object newValue) { | ||
return Objects.equals(bindingInitialValuesMap.get(binding), newValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here relies on equals
of the value type being implemented properly. That is something the Binder has not required before, so it's potentially a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it migh make more sense to add Binding-level API for overriding the logic for checking if value is reverted. That way if custom logic is needed, one does not need to extend Binder to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
introduced an equality predicate (I'm open for naming suggestions) that uses Objects::equals
as default, but it can be overridden in binding-level
@mshabarov This change will introduce a slight change in behavior of Binder change tracking due to requiring |
and deprecated the old handleFieldValueChange method
* @param equalityPredicate the predicate to use for equality comparison | ||
* @return this {@code BindingBuilder}, for method chaining | ||
*/ | ||
public BindingBuilder<BEAN, TARGET> withEqualityPredicate(SerializableBiPredicate<Object, Object> equalityPredicate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vote 4 default implementation; otherwise this is a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Quality Gate passedIssues Measures |
@@ -320,6 +321,8 @@ default BindingValidationStatus<TARGET> validate() { | |||
* changes, otherwise {@literal false}. | |||
*/ | |||
boolean hasChanges(); | |||
|
|||
SerializableBiPredicate<Object, Object> getEqualityPredicate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This misses Javadoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the type be instead TARGET
(data type of the binding), not Object
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -1810,6 +1850,7 @@ void setIdentity() { | |||
|
|||
private BindingExceptionHandler exceptionHandler = new DefaultBindingExceptionHandler(); | |||
|
|||
private Map<Binding<BEAN, ?>, Object> bindingInitialValuesMap = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the initial values would be a class field in the BindingImpl
instead and have a getter method in Binding
? Then you can call newly added method Binding::getInitialValue
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored the changes and removed bindingInitialValuesMap
. Now the initial value is kept in Binding level which is set during readBean.
I'd propose to set the equality predicate |
- removed bindingInitialValuesMap from Binder, and kept the initial value in binding level instead - removed the default implementation for equalityPredicate and now this feature will only be active if an equalityPredicate is set
I did the changes, however my only concern is now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but I haven't tested it.
I agree with the concern about having this API only on a binding level, would be good to allow doing the same for the whole form.
Just discussed with @tepi, the Binder-level API could be done in a way:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting to request changes
@onuridrisoglu fyi, I'll pick this up and do the changes |
Quality Gate passedIssues Measures |
Description
Fixes #19260
Type of change
Checklist
Additional for
Feature
type of change