vaadin / framework

Vaadin 6, 7, 8 is a Java framework for modern Java web applications.
http://vaadin.com/
Other
1.78k stars 730 forks source link

Feature Range in DateField #4174

Closed vaadin-bot closed 11 years ago

vaadin-bot commented 11 years ago

Originally by petr.franta


Hi.

I have two problems with new feature range in DateField:

  1. Function public void setResolution(Resolution resolution) in com.vaadin.ui.DateField call function updateRangeValidator(), which add new validator without checking settings start date and end date range. May be repair like this:

    public void setResolution(Resolution resolution) {
        this.resolution = resolution;
    
        if (getState(false).rangeStart != null || getState(false).rangeEnd != null) {
            updateRangeValidator();
        }
    
        markAsDirty();
    }
  2. Range validator (com.vaadin.data.validator.DateRangeValidator) supports only java.util.Date type. I use org.joda.time.DateTime in my beans and use custom converter for change java.util.Date to org.joda.time.DateTime. The problem is in class com.vaadin.data.validator.AbstractValidator - function "protected boolean isValidType(Object value)" which check value "return getType().isAssignableFrom(value.getClass());" and java.util.Date can't by assigned from org.joda.time.DateTime.\Superior validator function is "protected void validate(T fieldValue) throws Validator.InvalidValueException" for first step converted value java.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

vaadin-bot commented 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.

vaadin-bot commented 11 years ago

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>.

vaadin-bot commented 11 years ago

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.

vaadin-bot commented 11 years ago

Originally by @jdahlstrom


Fixed issue (1), reviewed by Leif Åstrand.

Might be useful to open a new enhancement ticket for issue (2).