Why is my Spring 3 Validator Validating Everything on the Model?

I guess this behaviour is not covered in the documentation well.

The problem is caused by the following:

  1. By default, @InitBinder-annotated method is called for each non-primitive model attribute, both incoming and outcoming (the purpose of calling it for outcoming attibutes is to allow you to register custom PropertyEditors, which are used by form tags when rendering a form).

  2. DataBinder.setValidator() contains a defensive check that call Validator.supports() and throws an exception if false is returned. So, there is no attempt to perform a validation, just an early check.

The solution is to restrict the scope of @InitBinder to particular attribute:

@InitBinder("whaleFormData")
protected void initBinder(WebDataBinder binder) { ... }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)