Results 1 to 3 of 3

Thread: Failed to convert property

Hybrid View

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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.

  3. #3

    Default

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

    Peter

Similar Threads

  1. ERROR: Context initialization failed
    By makhlo in forum Architecture
    Replies: 8
    Last Post: Jul 11th, 2008, 01:41 AM
  2. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  5. Replies: 2
    Last Post: May 13th, 2005, 05:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •