Results 1 to 3 of 3

Thread: Binding Numeric ID Field

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Posts
    7

    Default Binding Numeric ID Field

    I'm getting a bind error on my SimpleFormController. It's occuring on my property "id" which is a Long in my domain object. I'm getting this error upon submitting the form:

    Failed to convert property value of type [java.lang.String] to required type [java.lang.Long] for property 'id'; nested exception is java.lang.NumberFormatException: For input string: ""

    The error makes sense to me... it cannot bind to the "id" field because it can't convert "" to a Number using the NumberFormat.

    My desired effect here is to have the binder set id = null (or not set it at all). I would presume this would be the default behavior but I guess I'm wrong. Do I need to register a Custom Property Editor for every one of my id fields?

    I can't seem to find an example of a similar problem. Thanks for your time.

  2. #2

    Default Re: Binding Numeric ID Field

    Yeah, you would have to make a custom editor that checked for empty string values and converted them to null values in this case. There might be a property on the Long custom property editor in Spring, but I haven't looked at it in a long time. I got annoyed with this behavior too so I just added a feature into my framework that had a setting to allow null values or not, so it will throw the exception only when you want it to, but this setting is usable for longs, dates, booleans, user-defined types or whatever instead of just certain editors.

  3. #3
    Join Date
    Sep 2004
    Posts
    7

    Default

    Thanks for the quick reply. I looked through the Spring API Javadocs and found the CustomNumberEditor class.

    Here's how I'm using it:

    binder.registerCustomEditor(DomainObject.class,"id ",new CustomNumberEditor(Long.class,true));

    I've moved this code into an AbstractMyAppFormController class so that the "custom" binding of the empty String for null values is all in one place for the whole app.

Similar Threads

  1. Replies: 7
    Last Post: Sep 13th, 2005, 01:45 AM
  2. Replies: 4
    Last Post: Jun 14th, 2005, 09:28 PM
  3. Stop validation if binding fails.
    By sherihan in forum Web
    Replies: 0
    Last Post: Feb 8th, 2005, 03:18 AM
  4. Binding the "submit" field
    By general_pattonm in forum Web
    Replies: 2
    Last Post: Jan 22nd, 2005, 06:11 AM
  5. Replies: 2
    Last Post: Aug 17th, 2004, 04:16 PM

Posting Permissions

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