Thanks a lot for that, I really appreciate it. This is what I'm trying to do:
I'm trying to create a report that displays the validation errors and the number of times the validation errors occured.
For e.g. for the below xml
Code:
TitleIsMandatory - ErrorCount(2)
CostShouldBeGreaterThan3 - ErrorCount(1)
Code:
<itemList>
<item>
<title></title>
<cost>1.1</cost>
</item>
<item>
<title></title>
<cost>3.2</cost>
</item>
<item>
<title>someTitle</title>
<cost>3.5</cost>
</item>
</itemList>
The way I go about it is...
I add a payload to each constraint.
Code:
@NotNull(message = TITLE_EMPTY, groups = XmlAndExcelValidation.class, payload = { TitleIsMandatory.class })
public String getTitle() {
return title;
}
I then consolidate all the errors and group the errors by payload. This works fine for all the built in constraints. It would have worked fine even for my custom constraints/validators, but then I'm doing multiple validations inside some of my custom validators. Of course, it would have been ideal if I had done just one validation per constraint, but then in some cases, it made sense to group the validations together under the same constraint. I guess, since I cannot specify the payload dynamically in my validator, the best way to go about it is to refactor my custom validators so that each validator does only one validation. That will be quite a bit of work, I'm hoping there's a better way to do this :-) Thanks.
Cheers
Mark