
Untitled
By: a guest on
Jun 30th, 2012 | syntax:
None | size: 1.73 KB | hits: 23 | expires: Never
Spring numberformatting with registercustomereditor on list of numbers
NumberFormat numberFormat = getNumberFormat(0, 0, 2);
PropertyEditor propertyEditor =
new CustomNumberEditor(Double.class, numberFormat, true);
binder.registerCustomEditor(Double.class, "myDoubleField", propertyEditor);
public myController(PropertyEditorRegistrar customPropertyEditorRegistrar) {
this.customPropertyEditorRegistrar = customPropertyEditorRegistrar;
}
@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
customPropertyEditorRegistrar.registerCustomEditors(binder);
}
public final class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
// Double
PropertyEditor doubleEditor = getLocaleBasedNumberEditor(Double.class, true);
registry.registerCustomEditor(double.class, doubleEditor);
registry.registerCustomEditor(Double.class, doubleEditor);
}
binder.registerCustomEditor(Double.class, defaultEditor);
binder.registerCustomEditor(Double.class, "field1", specificEditor1);
binder.registerCustomEditor(Double.class, "field2", specificEditor2);
public class ListOfTimes {
private List<TimeStoredInSecondsSinceMidnight> times;
public static class TimeStoredInSecondsSinceMidnight {
private Integer id;
private Integer currentTime;
...
}
...
}
<form:input id="time" path="times[${count.index}].currentTime" size="5"/>
<form:input id="recordId" path="times[${count.index}].id" size="5"/>
binder.registerCustomEditor(Integer.class, propertyEditor);
binder.registerCustomEditor(Integer.class, "currentTime", propertyEditor);
binder.registerCustomEditor(Integer.class, "times.currentTime", propertyEditor);