dimanche 29 mars 2015

@InitBinder restricting to single validator

In my controller, when I set a validator to the webdatabinder:



@InitBinder
private void initBinder(WebDataBinder binder) {
binder.setValidator(validator);
}


My controller only applies that validator and ignore other fields' validation:



@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public void processRecord(@Valid @RequestBody Record record, Errors errors) {
//code
}


The field validation ignored are annotation based:



@NotNull
@Size(min = 2, max = 60, message="firstName must be between 2 and 60 characters long.")
private String firstName;


Is there a way to add the custom validator and still apply the default annotation based validation?


Aucun commentaire:

Enregistrer un commentaire