Search code examples
springspring-mvcspring-roo

Spring Roo: finder putting invalid date format in url


I have a Spring Roo mvc project going with a model called WorkOrder. I used the Roo shell to generate two finders for this model: findWorkOrdersByDateCompletedEquals and findWorkOrdersByDateCompletedBetween.

Problem: when I search using the findWorkOrdersByDateCompletedBetween, the minDateCompleted and maxDateCompleted parameters in the url are in the wrong format (the S- format)

.../workorders?find=ByDateCompletedBetween&minDateCompleted=2012-05-08&maxDateCompleted=2012-05-31

Here is the error from the debug log:

Failed to convert from type java.lang.String to type 
@org.springframework.web.bind.annotation.RequestParam
@org.springframework.format.annotation.DateTimeFormat java.util.Date for value '2012-05-15';

The funny thing is that the findWorkOrdersByDateCompletedEquals works just fine, and generates a url like this:

.../workorders?find=ByDateCompletedEquals&dateCompleted=May+30%2C+2012

What determines how these URLs get generated? The code is virtually identical between the two finders, why would they generate dates in different formats?


Solution

  • I found the real problem, it looks like it's a bug with Spring roo. There is a method in the controller .aj file that Roo didn't update:

    void addDateTimeFormatPatterns(Model uiModel) {
        uiModel.addAttribute("workOrder_datecompleted_date_format", DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
        uiModel.addAttribute("workOrder_maxdatecompleted_date_format", DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
        uiModel.addAttribute("workOrder_mindatecompleted_date_format", DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
    }
    

    Roo automatically put the "workOrder_datecompleted_date_format" attribute there, but I had to push in the method and add the maxdatecompleted and mindatecompleted attributes myself.