Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 1.73 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Spring numberformatting with registercustomereditor on list of numbers
  2. NumberFormat numberFormat = getNumberFormat(0, 0, 2);
  3. PropertyEditor propertyEditor =
  4.     new CustomNumberEditor(Double.class, numberFormat, true);
  5. binder.registerCustomEditor(Double.class, "myDoubleField", propertyEditor);
  6.        
  7. public myController(PropertyEditorRegistrar customPropertyEditorRegistrar) {
  8.     this.customPropertyEditorRegistrar = customPropertyEditorRegistrar;
  9. }
  10.        
  11. @Override
  12. protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)   throws Exception {
  13.     customPropertyEditorRegistrar.registerCustomEditors(binder);
  14. }
  15.        
  16. public final class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
  17.     // Double
  18.     PropertyEditor doubleEditor = getLocaleBasedNumberEditor(Double.class, true);
  19.     registry.registerCustomEditor(double.class, doubleEditor);
  20.     registry.registerCustomEditor(Double.class, doubleEditor);
  21. }
  22.        
  23. binder.registerCustomEditor(Double.class, defaultEditor);
  24. binder.registerCustomEditor(Double.class, "field1", specificEditor1);
  25. binder.registerCustomEditor(Double.class, "field2", specificEditor2);
  26.        
  27. public class ListOfTimes {
  28.    private List<TimeStoredInSecondsSinceMidnight> times;
  29.    public static class TimeStoredInSecondsSinceMidnight {
  30.       private Integer id;
  31.       private Integer currentTime;
  32.       ...
  33.    }
  34.    ...
  35. }
  36.        
  37. <form:input id="time" path="times[${count.index}].currentTime" size="5"/>
  38. <form:input id="recordId" path="times[${count.index}].id" size="5"/>
  39.        
  40. binder.registerCustomEditor(Integer.class, propertyEditor);
  41.        
  42. binder.registerCustomEditor(Integer.class, "currentTime", propertyEditor);
  43.        
  44. binder.registerCustomEditor(Integer.class, "times.currentTime", propertyEditor);