Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [databinding] custom validators(attach more than one validator)
[databinding] custom validators [message #648815] Fri, 14 January 2011 15:58 Go to next message
Rose-Red is currently offline Rose-RedFriend
Messages: 3
Registered: January 2011
Junior Member
Hi,

I have two custom validators and been trying to attach them to the same field, but one of them is being ignored.

Basically, the code below works fine. I am observing a text field and both of my custom validators are triggered properly.

bindingContext.bindValue(
				SWTObservables.observeText(nameText, SWT.FocusOut),
				EMFObservables.observeValue(person, Literals.PERSON__NAME),
				new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).
					setAfterConvertValidator(new RegularExpressionValidator("Steve\\d{1,}")).
					setAfterGetValidator(new MandatoryFieldValidator()), 
				null);


Now the following code seems to be ignoring IntegerValidator and shows the validation error that I have set up for the second validator. Here I am observing a number field and have created a custom converter as well which converts empty string into a null if needed or uses a default converter if the field is not empty.

bindingContext.bindValue(
				SWTObservables.observeText(ageText, SWT.FocusOut),
				EMFObservables.observeValue(person, Literals.PERSON_AGE),
				ageTargetStrategy.setAfterGetValidator(new IntegerValidator()).
					setAfterGetValidator(new RangedIntegerValidator(10, 50)),
				new UpdateValueStrategy().setConverter(NumberToStringConverter.fromInteger(true)));


RangedIntegerValidator is a subclass of the IntegerValidator. If I apply them separately, it works fine. Therefore, I wonder whether it is at all possible to have more than one validator attached to the same field.

I am a bit confused about setAfterGetValidator, setAfterConvertValidator and setBeforeSetVaidator methods. I have been playing around with all of them, but haven't got the satisfying result.

Any help would be appreciated
Re: [databinding] custom validators [message #649032 is a reply to message #648815] Mon, 17 January 2011 10:58 Go to previous messageGo to next message
Rose-Red is currently offline Rose-RedFriend
Messages: 3
Registered: January 2011
Junior Member
Can somebody please help me with this?
Re: [databinding] custom validators [message #649194 is a reply to message #648815] Tue, 18 January 2011 06:59 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2011-01-14 16:58, adrijukas@yahoo.com wrote:
> Hi,
>
> I have two custom validators and been trying to attach them to the same
> field, but one of them is being ignored.
>
> Basically, the code below works fine. I am observing a text field and
> both of my custom validators are triggered properly.
>
>
> bindingContext.bindValue(
> SWTObservables.observeText(nameText, SWT.FocusOut),
> EMFObservables.observeValue(person, Literals.PERSON__NAME),
> new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT).
> setAfterConvertValidator(new RegularExpressionValidator("Steve\\d{1,}")).
> setAfterGetValidator(new MandatoryFieldValidator()), null);
>
>
> Now the following code seems to be ignoring IntegerValidator and shows
> the validation error that I have set up for the second validator. Here I
> am observing a number field and have created a custom converter as well
> which converts empty string into a null if needed or uses a default
> converter if the field is not empty.
>
>
> bindingContext.bindValue(
> SWTObservables.observeText(ageText, SWT.FocusOut),
> EMFObservables.observeValue(person, Literals.PERSON_AGE),
> ageTargetStrategy.setAfterGetValidator(new IntegerValidator()).
> setAfterGetValidator(new RangedIntegerValidator(10, 50)),
> new
> UpdateValueStrategy().setConverter(NumberToStringConverter.f romInteger(true)));
>
> RangedIntegerValidator is a subclass of the IntegerValidator. If I apply
> them separately, it works fine. Therefore, I wonder whether it is at all
> possible to have more than one validator attached to the same field.
>
> I am a bit confused about setAfterGetValidator, setAfterConvertValidator
> and setBeforeSetVaidator methods. I have been playing around with all of
> them, but haven't got the satisfying result.
>
> Any help would be appreciated

setAfterGetValidator does set a single new validator, it does *not* add
one (thus the name), which is clearly documented. If you want to have
more than one validator per target, you should provide a validator that
refers to a collection of validators. Inside it's validate function it
will traverse through all referenced validators until the first status
is reported that is not an OK status.

Btw: This is not the same as MultiValidator. You will use
MultiValidator, if you want to ensure validation among *more* than one
target at the same time.

HTH & Greetings from Bremen,

Daniel Krügler
Re: [databinding] custom validators [message #649307 is a reply to message #649194] Tue, 18 January 2011 17:00 Go to previous message
Rose-Red is currently offline Rose-RedFriend
Messages: 3
Registered: January 2011
Junior Member
Thanks for the reply.
I used one validator after all and it does it's job in a similar fashion that you explained. I just wish there were more examples out there related to databinding, would have saved time Very Happy
Previous Topic:Only display one child of under a parent node in treeviewer
Next Topic:dialog java package
Goto Forum:
  


Current Time: Fri Apr 26 11:21:14 GMT 2024

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

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

Back to the top