Hi,
I am utilizing validate() methods for custom validation:
public class Foo {
// Fields...
public Map<String, List<ValidationError>> validate() {
// Validation logic here...
// return map so that I can create field errors
return map;
}
}
This is cool when I just validate Foo directly. However, when I nest Foo in another object that I validate I get into trouble:
public class Bar {
@Valid
public Foo foo;
}
What happens is that Foo's validate() method is not invoked when I validate Bar.
I have worked around this by calling Foo's validate from Bar's validate. But it gets a bit messy since I then need to alter field paths so that it points to the nested object (I create field errors, not global errors).
Is this by design or a bug?
Is there any other, better way to perform custom validation?
Knowing that Play takes care of invoking any validate() methods in nested objects when it's annotated with @Valid would be sooo much nicer. Plus if Play could take care of field paths when a field error is posted in a nested objects validate() method.
Joel