Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [Databinding] keeping the model in sync with validation
[Databinding] keeping the model in sync with validation [message #332894] Thu, 13 November 2008 01:15 Go to next message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
I'm using a DataBindingContext to create a simple binding a SWT Text and
a String WritableValue. The widget is hosted in a WizardPage and I am
using WizardPageSupport to track the validation.

My validation requirement is simple - the string should not be empty.
Using examples from snippets, I first accomplished this by using an
UpdateValueStrategy with a validateAfterGet IValidator. However, I
discovered that using this type of validation allows the UI and the
model to get out of sync. For example, if the widget has a single
character "A" and I delete it, the validation will cause the update to
fail and the model will retain the value "A" despite the widget now
being empty. I understand this behavior, since there are cases where
the model cannot accept the value in the UI at all. But I would prefer
they stay in sync in this case.

So my second attempt (which seems to be working) was to add a
MultiValidator to the DataBindingContext that validates the model
(WritableValue) directly. Is this the proper way to do it?
MultiValidator's name and javadoc do not imply that this use case was
envisioned.

Thanks,
Will
Re: [Databinding] keeping the model in sync with validation [message #332897 is a reply to message #332894] Thu, 13 November 2008 04:41 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
If you want to produce an error message but still allow the observables
to sync, then I think MultiValidator will do what you want. This isn't
exactly MultiValidator was designed for but hey, it works.

Matthew

Will Horn wrote:
> I'm using a DataBindingContext to create a simple binding a SWT Text and
> a String WritableValue. The widget is hosted in a WizardPage and I am
> using WizardPageSupport to track the validation.
>
> My validation requirement is simple - the string should not be empty.
> Using examples from snippets, I first accomplished this by using an
> UpdateValueStrategy with a validateAfterGet IValidator. However, I
> discovered that using this type of validation allows the UI and the
> model to get out of sync. For example, if the widget has a single
> character "A" and I delete it, the validation will cause the update to
> fail and the model will retain the value "A" despite the widget now
> being empty. I understand this behavior, since there are cases where
> the model cannot accept the value in the UI at all. But I would prefer
> they stay in sync in this case.
>
> So my second attempt (which seems to be working) was to add a
> MultiValidator to the DataBindingContext that validates the model
> (WritableValue) directly. Is this the proper way to do it?
> MultiValidator's name and javadoc do not imply that this use case was
> envisioned.
Re: [Databinding] keeping the model in sync with validation [message #332957 is a reply to message #332894] Mon, 17 November 2008 07:43 Go to previous messageGo to next message
Boris Bokowski is currently offline Boris BokowskiFriend
Messages: 272
Registered: July 2009
Senior Member
> My validation requirement is simple - the string should not be empty.
> Using examples from snippets, I first accomplished this by using an
> UpdateValueStrategy with a validateAfterGet IValidator. However, I
> discovered that using this type of validation allows the UI and the model
> to get out of sync. For example, if the widget has a single character "A"
> and I delete it, the validation will cause the update to fail and the
> model will retain the value "A" despite the widget now being empty. I
> understand this behavior, since there are cases where the model cannot
> accept the value in the UI at all. But I would prefer they stay in sync in
> this case.

I am confused - can the string be empty or not? When a binding has a
validation error, the observable values are out of sync (almost by
definition).

Is maybe what you want that the model is not updated on every key press, but
on FocusOut, or perhaps when the user presses Next/Finish?

Boris
Re: [Databinding] keeping the model in sync with validation [message #332974 is a reply to message #332957] Mon, 17 November 2008 16:26 Go to previous message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
I think he wants the model and target to stay in sync even if there is a
validation error.

Boris Bokowski wrote:
>> My validation requirement is simple - the string should not be empty.
>> Using examples from snippets, I first accomplished this by using an
>> UpdateValueStrategy with a validateAfterGet IValidator. However, I
>> discovered that using this type of validation allows the UI and the model
>> to get out of sync. For example, if the widget has a single character "A"
>> and I delete it, the validation will cause the update to fail and the
>> model will retain the value "A" despite the widget now being empty. I
>> understand this behavior, since there are cases where the model cannot
>> accept the value in the UI at all. But I would prefer they stay in sync in
>> this case.
>
> I am confused - can the string be empty or not? When a binding has a
> validation error, the observable values are out of sync (almost by
> definition).
>
> Is maybe what you want that the model is not updated on every key press, but
> on FocusOut, or perhaps when the user presses Next/Finish?
>
> Boris
>
>
Previous Topic:Re: Intro page independent of the product
Next Topic:References to a method
Goto Forum:
  


Current Time: Fri Dec 27 02:34:50 GMT 2024

Powered by FUDForum. Page generated in 0.03785 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top