Why isn't there a possibility to get old value from ValueChangeEvent
? It's rather expected from value change event to provide both old and new value.
Is there any build-in event type that would allow me to notify about value change and containing both old and new value? Is there any easy way to implement custom event like that without too much effort?
Ok, I solved it by implementing custom type to be used in application:
public class ValueChange<T> {
private final T oldValue;
private final T newValue;
public ValueChange(T oldValue, T newValue) {
this.oldValue = oldValue;
this.newValue = newValue;
}
public T getOldValue() {
return oldValue;
}
public T getNewValue() {
return newValue;
}
}
Now in our event source (e.g. custom control) we can implement interface in this way:
implements HasValueChangeHandlers<ValueChange<ValueType>>
And can fire events from our source this way:
private void fireValueChangeEvent(ValueType oldValue, ValueType newValue) {
ValueChangeEvent.fire(this, new ValueChange<ValueType>(oldValue, newValue));
}
So we can access both old value and new value on handler side. There was no need to implement new event type, hanlder type etc. We can keep using ValueChangeEvent
s which are semantically correct for our use case.