Consider below sample, which checks if fromDate and toDate are valid dates and if fromDate is less than toDate:
@CustomValidator(type = "DateValidator",
fieldName = "fromDate",
shortCircuit = true),
@CustomValidator(type = "DateValidator",
fieldName = "toDate",
shortCircuit = true),
@CustomValidator(type = "CompareDatesValidator",
message = "validate.date.jalali.same.or.before",
shortCircuit = true,
parameters = {
@ValidationParameter(name = "fromDateParam", value = "${fromDate}"),
@ValidationParameter(name = "toDateParam", value = "${toDate}")
})
The DateValidator extends the FieldValidatorSupport and the CompareDatesValidator extends the ValidatorSupport
Although I have shortCircuit the DateValidators, but the CompareDatesValidator always run, which is not correct. Can I fix this ?!
As explained in the documentation.
Then your actual execution order is:
fromDate)toDate)The problem is that it will be executed first, but since its check is a composite check based on two fields, the atomic check on the fields itself should be performed first.
But this is how the framework works, so you need to workaround it.
If your plain validator is still this one (even if with some modification), you could avoid the check and ignore the error in case the input is not valid, letting this validation happen where it belongs, in the Field Validators:
You only need to remember to always put the Field Validators in the same validation stack of the CompareDatesValidator, or the "Date not valid" errors will be silently swallowed.