Question about validating date values:
I added and Validator to a DateField. Thus I implemented the Interface Validator. As I catch terminal errors and leave the application, I saw, that this error is not handled right. Why an InvalidValueException is not catched like in other fields?
/** */
public class DateValidationApplication extends Application
{
private Window m_mainWindow;
private PopupDateField m_dateField;
/**
* {@inheritDoc}
*/
@Override
public void init ()
{
m_mainWindow = new Window("DateValidation");
m_dateField = new PopupDateField("Date");
m_dateField.addValidator(new Validator(){
public void validate (Object value) throws InvalidValueException
{
Date date = (Date) value;
if (date != null && date.before(new GregorianCalendar(2000, 0, 1).getTime()))
{
throw new InvalidValueException("Out of range!");
}
}
public boolean isValid (Object value) {
try {validate(value);} catch (InvalidValueException e) {
return false;
}
return true;
}
});
m_dateField.setImmediate(true);
m_dateField.setLocale(Locale.ENGLISH);
m_mainWindow.addComponent(m_dateField);
m_mainWindow.addComponent(new Button("Next"));
setMainWindow(m_mainWindow);
}
/**
* {@inheritDoc}
*/
@Override
public void terminalError (com.vaadin.terminal.Terminal.ErrorEvent event)
{
m_mainWindow.addComponent(new Label("Terminal Exception catched: "
+ event.getThrowable().getMessage()));
m_dateField.setValue(null);
}
}