Catch and modify DateField format exception

Hi all,

I have a problem.
I want to add an error message on all my PopupDateFields, which says “Bad format, you must enter date like ‘DD/MM/YY’ …”

Actually i have Vaddin exception :

com.vaadin.data.Property$ConversionException

How can i catch and change this error ?

Thanks by advance !

I did it this way: extending the DateField and overriding the handleUnparsableDateString(String) method. Please share it with us if you do a better job with this method.


public class MyDateField extends DateField {

// [...]


	@Override
	protected Date handleUnparsableDateString(String dateString) throws ConversionException {
		Window w = getWindow();
		if (w != null) {
			w.showNotification("Data \"" + dateString + "\" inválida!");
		}
		return null;
	}

Best regards,
Dalton

Ok thanks i can do that …

I had try do find a way without redefining my own components.

But if it is the only way, i’ll do that …

Thanks !

I tried to make DateField to return the value that field contained before entering new text value if new value can’t be parsed. I tried to do it overriding handleUnparsableDateString like this:

	@Override
	protected Date handleUnparsableDateString(String dateString)
			throws ConversionException {
		
		requestRepaint(); 
		return (Date) getValue(); 
	}

It works on first attempt but when I enter the exact same unparsable value again, it clears the field (If I enter different unparsable values it’s not cleared). Little debugging showed me that dateString field in DateField class is set in changeVariables method and DateField “remembers last unparsed value”. Before calling handleUnparsableDateString, there is comparison !dateString.equals(oldDateString) which prevents calling the method if currently entered unparsable value is same than earlier entered. In this case it calls setValue and passes there null.

I think the dateString field should be cleared if handleUnparsableDateString method handles the situation. While the dateString field is private I can’t even clear it manually. Should I make a ticket of this?

Sorry for the late reply.

Indeed, there seems to be a bug here, and you can make a ticket of the problem.
I would have to check to see if clearing the field would be the correct solution.

Ticket created:

http://dev.vaadin.com/ticket/4263

Hi,

did anyone get the fix to work? I downloaded the fixed class and compiled it. The result is that - no matter if I throw an exception or not - the broken value is removed from the DateField on the client.

Is anything apart from compiling the DateField class required to get this working?

Thanks in advance for any assistance.