1

I have a problem with a Date Validation. It works only at the begining. After I put a date and delete it once again it stop working. With the String field it works. Besides I wish to use 2 Validators but it detects only one Could someone help me or give me a hint?

First I define in my DateEditor that I need a validation:

@Override
public void setConfiguration(EditorConfiguration editorConfiguration) {
    Validator<LocalDate> validator = ((DateFieldConfiguration) editorConfiguration).getValidator();
    Validator<LocalDate> validator2 = ((DateFieldConfiguration) editorConfiguration).getValidator2();
    if (validator != null && validator2 != null) {
        binder.forField(this).withValidator(validator).withValidator(validator2).asRequired("Mandatory")
                .bind(s -> getValue(), (b, v) -> setValue(v));

    }
}

In my questions configuration I added a Validators methods:

private Validator<LocalDate> dateRequiredValidator() {

    return Validator.from(v -> v != null,
            "Feld darf nicht leer sein");
}

private Validator<LocalDate> dateNotAllowedValidator() {
    LocalDate today = LocalDate.now();
    return Validator.from(v -> !(v.isAfter(today)),"Datum kann nicht in der Zulunft sein");
}

and I assure that I will execute

question.setEditorConfiguration(new DateFieldConfiguration(dateRequiredValidator(),dateNotAllowedValidator()));

I tried that solution with my String Field and everything works like a charm

Anna K
  • 1,666
  • 4
  • 23
  • 47
  • Is `EditorConfiguration` and `DateFieldConfiguration` your own code, or from some library? – Basil Bourque Oct 19 '17 at 04:59
  • It is my own code. I define an overall validators in editor configuration file – Anna K Oct 19 '17 at 07:15
  • Instead of posting calls to your own unseen libraries, post something we can work with, an [MCVE – Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Basil Bourque Oct 19 '17 at 14:37

0 Answers0