Spring Framework
  1. Spring Framework
  2. SPR-10097

Date variables in forms are failing with joda conversion error

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 3.2 GA
    • Fix Version/s: 3.2.2
    • Component/s: None
    • Labels:
      None

      Description

      From the form post:

      I upgraded from Spring 3.1.2 to 3.2

      After upgrade, all my date variables in forms are failing with joda conversion error.

      org.springframework.core.convert.ConverterNotFound Exception: No converter found capable of converting from type java.util.Date to type org.joda.time.ReadableInstant
      

      Sample Code:

      Its failing with any of the following options.

      <form:input id="startDt" path="startDt" value="2012-10-12" />
      <form:input id="startDt" path="startDt" value="10-12-2012" />
      <form:input id="startDt" path="startDt" value="10/12/2012" />
      

      Note: startDt is of type java.util.Date

        Issue Links

          Activity

          Hide
          Srinivasa Attaluri added a comment -

          Here is the error log.

          startDt is of type java.util.Date in the model.

          Show
          Srinivasa Attaluri added a comment - Here is the error log. startDt is of type java.util.Date in the model.
          Hide
          Srinivasa Attaluri added a comment -

          Got the problem fixed by adding the following code in the Controller.

          @InitBinder
          public void initBinder(WebDataBinder binder)

          { CustomDateEditor dateMMddyyyy = new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true); binder.registerCustomEditor(Date.class, dateMMddyyyy); }
          Show
          Srinivasa Attaluri added a comment - Got the problem fixed by adding the following code in the Controller. @InitBinder public void initBinder(WebDataBinder binder) { CustomDateEditor dateMMddyyyy = new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true); binder.registerCustomEditor(Date.class, dateMMddyyyy); }
          Hide
          Phil Webb added a comment -

          Hi Srinivasa,

          That is good that you have a work around. I am still planning to look at this to see what has changed to cause the problem. Another option might be to use the @DateTimeFormat annotation or configure a global date format [1]. Support for a global date format was added in Spring 3.2 and I have a suspicion that this change might be a contributing factor.

          From your log file, I assume that you have joda time on your classpath?

          [1] http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/validation.html#format-configuring-formatting-globaldatetimeformat

          Show
          Phil Webb added a comment - Hi Srinivasa, That is good that you have a work around. I am still planning to look at this to see what has changed to cause the problem. Another option might be to use the @DateTimeFormat annotation or configure a global date format [1] . Support for a global date format was added in Spring 3.2 and I have a suspicion that this change might be a contributing factor. From your log file, I assume that you have joda time on your classpath? [1] http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/validation.html#format-configuring-formatting-globaldatetimeformat
          Hide
          Srinivasa Attaluri added a comment -

          I do have JodaTime in the classpath. However, I am not using it in this context.

          I do not want to use @DateTimeFormat as it it s attribute level annotation and that requires a lot of testing.

          Tried using global configuration and had different issues. (May be I was missing something).

          I stopped other options as I have a workaround that I could use in the BaseController.

          As you mention, it would be helpful to get the bug fixed so it would be backward compatible.

          Show
          Srinivasa Attaluri added a comment - I do have JodaTime in the classpath. However, I am not using it in this context. I do not want to use @DateTimeFormat as it it s attribute level annotation and that requires a lot of testing. Tried using global configuration and had different issues. (May be I was missing something). I stopped other options as I have a workaround that I could use in the BaseController. As you mention, it would be helpful to get the bug fixed so it would be backward compatible.
          Hide
          Phil Webb added a comment -

          The fixes for SPR-10198 and SPR-10105 should fix this issue.

          Show
          Phil Webb added a comment - The fixes for SPR-10198 and SPR-10105 should fix this issue.

            People

            • Assignee:
              Phil Webb
              Reporter:
              Phil Webb
              Last updater:
              Phil Webb
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                1 year, 10 weeks, 2 days ago