Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[riena-dev] Comments regarding Validation

I just finished adding validation to the SWT text ridget. Below are a
couple of comments with regard to the validation APIs (IEditableRidget)
and the text field.

1. Currently no re-validation is performed when adding / removing
validation rules. Consider this:

ridget.addValidationRule(numbersOnly)
ridget.setText("abc"); // invalid

but

ridget.setText("abc");
ridget.addValidationRule(numbersOnly); 
// valid until the user changes the text or the next setText()

We should consider if this is acceptable. At the minimum it should be
documented. If we want to change it we have to think about re-validating
with every add / remove rule or if there should be some kind of
revalidate() method.


2. Currently validation is mostly concerned with the text that is
entered by the user. However in reality there are 4 ways the text can
change:

a. keyboard entry 
b. ((Text)ridget.getUIControl()).setText() // equivalent to a; will not
be discussed further
c. ridget.setText("foo")
d. ridget.bindToModel(myBean); myBean.setValue("foo");
ridget.updateFromModel();

According to my understanding of the existing code cases c. and d. are
not handled. Christian and I discussed this on the phone. My current the
SWT implementation follows the behavior described below. I welcome your
thoughs (esp. if you are familiar with the swing implementation).

[case a+b]

user types in widget
-> on edit validation -> update ridget text
-> focus lost / CR -> on update validation -> update model

[case c]
ridget.setText()
-> on edit and on update validation
if !ok -> throw runtime exception; widget, ridget, model unchanged
if ok	 -> update widget and model; widget, ridget, model have same
value

[case d]
model.setValue("xxx"); ridget.updateFromModel()
-> on edit and on update validation
if !ok -> throw runtime exception; widget and ridget unchanged
if ok -> update widget and ridget; widget, ridget, model have same value


3. Some existing validation rules seem to be too strict because they
block partial values that are incorrect. However while inputting
character-by-character we start with a partial value that is not correct
(example email) but will be correct after the input is finished. 

Example #1: see bug 236990.
Example #2: new ValidExpression(GERMAN_ZIP); This requires five digits.
Editing 12345 to 12346 is ok. Entering 12345 character by character is
currently not possible.

How was this handled in the past?

I welcome your insights.

Kind regards,
Elias.



Back to the top