Announcement Announcement Module
Collapse
No announcement yet.
Custom Editors for Date and Double objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Editors for Date and Double objects

    I have problems with converting/formatting java.util.Date and java.lang.Double objects.

    Date objects don't get the right format when loading. I've registered a CustomDateEditor with

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    binder.registerCustomEditor(Date.class, null, new CustomDateEditor(dateFormat, true));

    When loading the form, the field value shows up as "yyyy-MM-dd".

    The second problem is with Double objects registered like

    binder.registerCustomEditor(Double.class, null, new CustomNumberEditor(Double.class, nf, true));

    When submitting a value like "98.99" in the form, Spring saves "9899".

    After reloading the value looks like "9899.0".

    How can I use these two object types in Spring ?

  • #2
    If your Locale is German, I think your default numbers have a comma instead of a dot to indicate the decimal place (e.g. 98.99 will give 9899.0) - try entering 98,99. Look at changing the Locale or java.text.DecimalFormatSymbols to change this.

    With the date, can you provide more information. I'm not sure why this would occur.

    Comment

    Working...
    X