Validation and ValueChangeEvent

In which order are they processed? It seems like the ValueChangeEvent happens before Validation. In my case, I want to validate my TextField, and if it passes the validation, only then is the ValueChangeEvent fired, to do the stuff I really want to do it.

So, to describe what I’m trying to do, I have a TextField that I know I want to be formatted as an integer. So, I add my own Validator to that textfield that handles everything as it should. I also call textField.setValidationVisible(true). I also add a value change listener (shared with other components). If everything I get is formatted correctly, I pass this data to a database for storage.

Is there a more correct way to achieve what I want to do?

ValueChange happens before validation if you use automatic validation (it validates it on paint).

You can also validate when ever you want using AbstractField#isValid.

I suggest adding direct datasource to Integer. Only valid values are pushed to datasource.

Eg textfield.setPropertyDataSource(new MethodProperty(mypojo, “number”));

So, setPropertyDataSource() being not familiar to me from before, I understand that this binds a direct connection between a pojo’s property and the stuff entered to a field. Am I right?

In that case, i don’t have such a pojo to bind this to, as this is a generic method that works for and with many different stuff. I think I’ll try the isValid()-way…

Yep, it binds it directly to pojo’s property. Changes to fields, changes values in pojos. Its really useful since you can do this:

public class MyPojo {
   private double sum;
   private Date startDate
   private Date endDate;
   private int cout;
}

And bind diffent fields directly to that pojo: 2x DateFields and 2x TextFields.

Sounds like best solution for your. Note that you can set validationVisible(false) and do validation manually when valuechange occurs. To do it manually use AbstractField#validate and catch its error to errorcomponent.


try {
  field.validate
} catch (InvalidValueException e) {
  field.setComponentError(new UserError(e.getMessage));
}