1. Added this to my resources.groovy
configurer(org.springframework.beans.factory.config.CustomEditorConfigurer) {2. Create a class that implements PropertyEditorRegistrar
propertyEditorRegistrars = [ref("registrar")]
}
registrar(com.sungard.stallion.format.CustomPropertyEditorRegistrar)
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
public class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(java.math.BigDecimal.class, new CurrencyPropertyEditor());
}
}
3. It seems like this could have been done in a single step... but also define the class that the Registrar adds which implements PropertyEditor. Spring provides a helper class, PropertyEditorSupport, that the custom editor can extend:
import java.math.BigDecimal;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorSupport;
public class CurrencyPropertyEditor extends PropertyEditorSupport implements PropertyEditor {
public void setAsText(String text) {
setValue(... parsing goes here...);
}
public String getAsText() {
Object value = getValue();
if (value instanceof BigDecimal) {
return ... formatting goes here...;
}
return ("" + value);
}
}
- Ben Hidalgo
No comments:
Post a Comment