Announcement Announcement Module
No announcement yet.
Binding errors in 1.1 RC1+ Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding errors in 1.1 RC1+

    I just noticed a change in SpringMVC binding (works in 1.0.2, does not work in 1.1 RC1+):

    My command object has a map of Parameter objects. The Parameter class has property with a method signatures like this:

    Object getValue()
    void setValue(Object value)
    I am registering a custom property editor for each Parameter instance in the map. For example:

    String paramName = "parameterMap[start_date].value";
    binder.registerCustomEditor(Date.class, paramName, getDateEditor());
    In 1.0.2 this works fine--the value entered by the user is converted to an instance of Date and is bound to the value property of parameter. However, in 1.1 RC1 this does not work--a String containing the value entered by the user is bound to the value property of the parameter (not a Date). It looks like the registered property editor is bypassed and the user-submitted value is assigned directly to the "value" property. Maybe this has something to do with the fact that both String and Date are subclasses of Object.

    Note, the version of Spring I am using was checked out of CVS and compiled on 8/12/2004, hence the "+" on 1.1 RC1+.[/code]

  • #2
    I thought...


    Was just thinking.... does this issue maybe have something to do with my problem.... also trying to bind a value from a Map to a property editor.... but it seems as if the editor does not exist or isn't registered... strange.
    Last edited by Rod Johnson; Jan 18th, 2006, 11:09 AM.


    • #3
      I've just fixed the corresponding check to allow for this case: The check has changed in the 1.1 codebase, having become slightly more strict.

      Essentially, the editor did not kick in because you registered it for Date, and your property type Object is not assignable to Date. I've simply relaxed that check (for some cases where it doesn't break semantics).

      Note that the following should work in 1.1 RC1 too: If you don't register for a specific type but just for a property name, your editor will kick in.

      String paramName = "parameterMap[start_date].value"; 
      binder.registerCustomEditor(null, paramName, getDateEditor());


      • #4
        Thanks Juergen. I never thought of not specifying a type, that's a good idea.

        I've simply relaxed that check (for some cases where it doesn't break semantics).
        Does that mean that you recommend doing it the way I was when I found the problem, or is it better to not specify the type in a case where the target bean property is more general than the type returned by the editor? ...did that make sense?