Announcement Announcement Module
Collapse
No announcement yet.
Validation ignored w/CustomNumberEditor; Q? on my solution. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation ignored w/CustomNumberEditor; Q? on my solution.

    Hi all,

    I've noticed that my custom validator is ignored on form input fields which accept numeric values. Instead of displaying my custom error message, the form shows a NumberFormatException.

    We've traced this behavior back to the CustomNumberEditor, and realized that the editor automatically attempts to convert the input string to the desired numeric value, and sets the error in the process when, for example, the value is null.

    We've devised a work around by explicitly registering the CustomNumberEditor in the controller:
    Code:
    		binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, true));
    This sets the "allowEmpty" property of the controller to true, and allows my custom validator to do it's thing.

    For some reason, this seems to be a bit of a hack rather than the intended behavior/use of the CustomNumberEditor and a custom validator.

    Is this the accepted way of handling this situation? or is there some other way you do this?
Working...
X