PDA

View Full Version : Failed to convert property



pak
Sep 14th, 2004, 01:35 PM
Hi there

I have a form where the user can enter various items of data, and submit to a controller.

My problem is that some of the fields bind to numeric types (Double) or Date for example. And these cause "failed to convert property" errors if the user does not enter anything. I guess that somewhere before the data gets to the onSubmit method in the controller it is converted to the appropriate type - and that's where for example a NumberFormatException can occur.

How can I intercept and control these conversions, or otherwise repress these errors?

Thanks,
Peter

Alef Arendsen
Sep 14th, 2004, 01:41 PM
Register custom editors (extending PropertyEditorSupport) in the initBinder() method of the controller you're using (override it).

Spring provides a couple of PropertyEditors out of the box (such as a CustomDateEditor taking a DateFormat). They're in the package org.springframework.beans.propertyeditors.

pak
Sep 14th, 2004, 03:17 PM
Great, thanks. Really easy when you know how. The custom editors supplied with Spring are just what I need.

Peter