| Multivalidator fires validate method twice [message #892868] |
Sat, 30 June 2012 16:17  |
Roman Smushkevich Messages: 4 Registered: June 2012 |
Junior Member |
|
|
Hi everybody,
During programming investigations I met really uncomfortable behaviour of anonymous class descended from MultiValidator. Its validate method is fired twice every time the SWTWidget is changed.
Particularly I placed 2 DateTime widgets onto the form and assigned observablevalue to each of them. Afterwards I introduced an anonymous class descended from MultiValidator and used those 2 observable values to check constraints according to the shared examples.
So, after implementation I recognized the uncommon behaviour of my backed class. The valid method fires twice on each change of the date in any of the DateTime widgets . If I insert a call to JPA or whatever else, its behaviour could lead to a performance regression.
If I had made a mistake in a code snippet or if this is due to a bug in a JFace binding mechanism - let me know or please make a suggestion about such "misbehaviour".
DataBindingContext bindingContext = new DataBindingContext();
final IObservableValue getDishIDObserveValue = PojoObservables.observeValue(getDish(), "id");
//
final IObservableValue dteStartDateObserveSelectionObserveWidget = SWTObservables.observeSelection(dteStartDate);
final IObservableValue dteEndDateObserveSelectionObserveWidget = SWTObservables.observeSelection(dteEndDate);
//
MultiValidator dateValidator = new MultiValidator() {
@Override
protected IStatus validate() {
Integer id = (Integer)getDishIDObserveValue.getValue();
if (id == null)
id = -1;
Date startDate = (Date)dteStartDateObserveSelectionObserveWidget.getValue();
Date endDate = (Date)dteEndDateObserveSelectionObserveWidget.getValue();
return Status.OK_STATUS;
}
};
bindingContext.addValidationStatusProvider(dateValidator);
//
return bindingContext;
|
|
|
|
| Re: Multivalidator fires validate method twice [message #892948 is a reply to message #892911] |
Mon, 02 July 2012 02:32  |
Roman Smushkevich Messages: 4 Registered: June 2012 |
Junior Member |
|
|
Hi Jan,
Before posting my question in this thread I searched for a solvation in Internet. Thanks for the link any way, but it doesn't answer my question.
From the other side you are right. Multivalidator registers itself. BUT the validate method fires twice for each value change in each validator. This means, that when I'm shifting a date only in DateTimeWidget "dteStartDate" it occures 2 runs through valid method.
But anyway, thanks for your help!
|
|
|
Powered by
FUDForum. Page generated in 0.01757 seconds