Created
June 12, 2013 11:34
-
-
Save robmazan/5764545 to your computer and use it in GitHub Desktop.
Spring Controller initBinder method with custom date format setup + IllegalArgumentExeption details suppressed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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