Announcement Announcement Module
Collapse
No announcement yet.
Failed to convert property Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Failed to convert property

    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

  • #2
    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.

    Comment


    • #3
      Great, thanks. Really easy when you know how. The custom editors supplied with Spring are just what I need.

      Peter

      Comment

      Working...
      X