use of com.vaadin.data.Validator in project VaadinUtils by rlsutton1.
the class DateTimePickerInline method createTextDateField.
private TextField createTextDateField() {
final TextField displayDate = new TextField();
// add validator to text date field
displayDate.addValidator(new Validator() {
private static final long serialVersionUID = 1L;
@Override
public void validate(Object value) throws InvalidValueException {
try {
Date date = dateFormatter.parse((String) value);
datePicker.setValue(date);
} catch (ParseException e) {
throw new InvalidValueException(e.getMessage());
}
}
});
// add value change listener to text date field
displayDate.addValueChangeListener(new ValueChangeListener() {
private static final long serialVersionUID = 1L;
@Override
public void valueChange(Property.ValueChangeEvent event) {
try {
Date date = dateFormatter.parse((String) event.getProperty().getValue());
datePicker.setValue(date);
} catch (ParseException e) {
// do nothing, well handle this in a validator
}
}
});
return displayDate;
}
use of com.vaadin.data.Validator in project VaadinUtils by rlsutton1.
the class ReportParameterDateTimeRange method createValidators.
void createValidators() {
startfield.addValidator(new Validator() {
private static final long serialVersionUID = 1L;
@Override
public void validate(Object value) throws InvalidValueException {
if (value == null) {
throw new InvalidValueException("Start date is invalid");
}
if (endfield.getValue() != null && ((Date) value).after(endfield.getValue())) {
throw new InvalidValueException("Start date must be before the end date");
}
}
});
endfield.addValidator(new Validator() {
private static final long serialVersionUID = 1L;
@Override
public void validate(Object value) throws InvalidValueException {
if (value == null) {
throw new InvalidValueException("End date is invalid");
}
if (startfield.getValue() != null && ((Date) value).before(startfield.getValue())) {
throw new InvalidValueException("Start date must be before the end date");
}
}
});
}
Aggregations