[DataBinding] Validation : why 2 methods [message #447584] |
Tue, 11 April 2006 03:59  |
Eclipse User |
|
|
|
If i need to signal on my UI a required field, i want to put a red star
for example on the right of the field, and when the user write something
the star disappear.
To do that i began to write this code :
Text myTextField = ...
Label myValidationRedStar = ...
final Binding binding = dbc.bind(myTextField ,
new Property(myObject, "myKey"),
new BindSpec(null,
null,
new RequiredValidator(),
null));
dbc.bind(myValidationRedStar ,
binding.getPartialValidationError(),
new BindSpec().setUpdateModel(false));
where RequiredValidator contains :
public ValidationError isPartiallyValid(Object value) {
if (value == null ||
(value instanceof String && value.toString().length() == 0)) {
return ValidationError.warning("*");
}
return null;
}
Unfortunatelly it not works, because the event associated with the call
of the isPartiallyValid() not drive a refresh on the screen.
Then i put the binding on the validationError :
dbc.bind(myValidationRedStar ,
binding.getValidationError(),
new BindSpec().setUpdateModel(false));
and add :
binding.getPartialValidationError().addChangeListener(new
IChangeListener() {
public void handleChange(IObservable source) {
binding.getValidationError().setValue(((IObservableValue)
source).getValue());
}
});
then it works. Maybe i make a mistake in the first case but i think that
maybe it will be better to have just one validation method and select
the event associated with (like a style in swt : KEY_PRESSED |
FOCUS_OUT). How do you see this use case and what do you thinking about ?
|
|
|
Re: [DataBinding] Validation : why 2 methods [message #447617 is a reply to message #447584] |
Tue, 11 April 2006 23:46  |
Eclipse User |
|
|
|
Sébastien Letélié wrote:<snip/>
> then it works. Maybe i make a mistake in the first case but i think that
> maybe it will be better to have just one validation method and select
> the event associated with (like a style in swt : KEY_PRESSED |
> FOCUS_OUT). How do you see this use case and what do you thinking about ?
I think that in the end you figured out the way we intended for you to
do it. There are two steps in getting a visible error:
1) Return a warning or error from a validator.
2) Bind some UI object to the binding.getPartialValidationError()
IObservable, which you did manually by adding a change listener. You
could also have bound it using data binding to your label since it's
already an IObservable.
Hope this helps!
Regards,
Dave Orme
--
Visual Editor Project lead
http://www.coconut-palm-software.com
http://www.db4o.com -- The Open-source Java Object Database
|
|
|
Powered by
FUDForum. Page generated in 0.03608 seconds