Skip to content

Instantly share code, notes, and snippets.

@robmazan
Created June 12, 2013 11:34
Show Gist options
  • Save robmazan/5764545 to your computer and use it in GitHub Desktop.
Save robmazan/5764545 to your computer and use it in GitHub Desktop.
Spring Controller initBinder method with custom date format setup + IllegalArgumentExeption details suppressed.
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
binder.setBindingErrorProcessor(new DefaultBindingErrorProcessor() {
@Override
public void processPropertyAccessException(PropertyAccessException ex, BindingResult bindingResult) {
String propertyName = ex.getPropertyName();
Object value = ex.getValue();
bindingResult.addError(new FieldError(bindingResult.getObjectName(), propertyName, value, true,
new String[] { "moderation.field.error" }, new Object[] { propertyName, value },
"Invalid value for " + propertyName + "(" + value + ")"));
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment