1
votes

I'm using Springs annotations based form validation (mainly @NotBlank and @Length) which works great. I'm passing the formbean into the validation method like so:

validate(formBean, result);

I have several annotations attached to various form fields which are validating as expected apart from one.

One of my fields in the form bean is declared like so:

private EntriesBean entries;

This field obviously refers to a bean which has the usual getters and setters. A couple of the fields within this bean also have the validation annotations attached but they do not validate as part of the validate() method call like the other fields do. Is this something to do with this bean being referred to from another bean rather than directly from the method that calls validate() ?

Thanks

2

2 Answers

0
votes

You can validate your "entries" field this way:

@Valid
private EntriesBean entries;

This will make Hibernate validator cascade the validations in that bean

0
votes

Answered my own question.

Reading the very lengthy documentation I can see that the way to do this is to use the pushNestedPath() and popNestedPath() methods of the BindingResult object like so:

    result.pushNestedPath("entries");
    validator.validate(form.getEntries(), result);
    result.popNestedPath();

I don't like this way of doing it as it looks quite messy but it works, it appears