Closed vaadin-bot closed 11 years ago
Originally by cmj
Same problem here with DateRangeValidator. If I try to add a conversion to string, that string is validated by the DateRangeValidator and always causes "Date is out of allowed range".
If such conversions are not possible inside a datefield, maybe there should exist some PropertyWrapper for backing properties that supports conversion.
Originally by @jdahlstrom
Just checking - are you actually seeing erroneous behaviour related to (1), or is it simply a minor performance problem? ISTM DateRangeValidator
always returns true if both ends of the range are null.
As for (2), there's a generic architectural issue in Vaadin that validators are always run on the converted value, even though in some cases it would be useful to validate the original. This seems to be one of those cases. As a simple fix, perhaps there should be a protected createDateRangeValidator()
in DateField
that could be overridden to return a custom RangeValidator<MyDateType>
.
Originally by petr.franta
(1) this is not only performance problem, because if you call function DateField.setResolution()
without setting start and end dates range, validator show error "Date is out of allowed range" for non java.util.Date type. Function updateRangeValidator() allways initialize DateRangeValidator. When you use other date type as MyDateType
, you will always need to override RangeValidator<MyDateType>
, even if it is not needed.
Originally by @jdahlstrom
Fixed issue (1), reviewed by Leif Åstrand.
Might be useful to open a new enhancement ticket for issue (2).
Originally by petr.franta
Hi.
I have two problems with new feature range in DateField:
Function
public void setResolution(Resolution resolution)
incom.vaadin.ui.DateField
call functionupdateRangeValidator()
, which add new validator without checking settings start date and end date range. May be repair like this:Range validator (
com.vaadin.data.validator.DateRangeValidator
) supports onlyjava.util.Date
type. I useorg.joda.time.DateTime
in my beans and use custom converter for changejava.util.Date
toorg.joda.time.DateTime
. The problem is in classcom.vaadin.data.validator.AbstractValidator
- function "protected boolean isValidType(Object value)
" which check value "return getType().isAssignableFrom(value.getClass());
" andjava.util.Date
can't by assigned fromorg.joda.time.DateTime
.\Superior validator function is "protected void validate(T fieldValue) throws Validator.InvalidValueException
" for first step converted valuejava.util.Date
by "getConverter().convertToModel(fieldValue, getModelType(), getLocale())
" and for next step iterates all validators for "validate(valueToValidate)
".Imported from https://dev.vaadin.com/ issue #12193