Results 1 to 2 of 2

Thread: Dates are broken in controller methods after upgrading from 3.0.6 to 3.2

  1. #1
    Join Date
    Jan 2011
    Posts
    12

    Default Dates are broken in controller methods after upgrading from 3.0.6 to 3.2

    This was working in 3.0.6 but in 3.2.1 the date is no longer loaded into trackingDto and is null. I have verified that it is still coming in on the web request (in the format 'yyyy-MM-dd'):

    In controller, this just worked in 3.0.6 with no problem but won't work anymore in 3.2.1:
    Code:
    @RequestMapping(value = "/track", method = RequestMethod.POST)
    public String trackPurchase(@Valid TrackingDto trackingDto, BindingResult result, HttpSession session, Model model) {
        trackingDate = trackingDto.getDate(); // is present on request but null here
        // etc.
    }
    TrackingDto:
    Code:
    public class TrackingDto {
        private Department department;
        private Date date;  // java.util.Date
    
        public Date getDate() {
            return date;
        }
        public void setDate(Date emailDate) {
            this.emailDate = emailDate;
        }
        public Department getDepartment() {
            return department;
        }
        public void setDepartment(Department department) {
            this.department = department;
        }
    }
    I tried registering CustomDateEditor in a new @InitBinder method in my controller as follows but it didn't work (even though I verified that the method is being called on the requests):
    Code:
    @InitBinder
    public void initListBinder(WebDataBinder binder) {
        binder.setAutoGrowCollectionLimit(2000);
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        CustomDateEditor dateEditor = new CustomDateEditor(dateFormat , false);
        binder.registerCustomEditor(java.util.Date.class, dateEditor);
    }
    I also tried a custom registrar, but it is not working in my controller:
    Code:
    private final PropertyEditorRegistrar customPropertyEditorRegistrar;
    
    public TrackingController(PropertyEditorRegistrar propertyEditorRegistrar) {
        this.customPropertyEditorRegistrar = propertyEditorRegistrar;
    }
    
    @InitBinder
    public void initListBinder(WebDataBinder binder) {
        binder.setAutoGrowCollectionLimit(2000);
        this.customPropertyEditorRegistrar.registerCustomEditors(binder);
    }
    I can't find anything else on the web or in the doc to try. Is there no one else who has tried to upgrade their version of Spring and had simple dates quit working in their controllers? Thx in advance.

  2. #2
    Join Date
    Jan 2011
    Posts
    12

    Default

    I found my problem. I had a lurking import of java.sql.Date instead of java.util.Date. What appears to be the case is that the default date property editor >= spring 3.1.x will no longer support java.sql.Date.

Posting Permissions

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