I have a specific scenario where I can only check for violation conditions manually, at a later point in the flow.
What I want to do is throw a ConstraintViolationException
, and provide a "real" ConstraintViolation object
to it (when I catch the exception up the stack, I use the #{validatedValue}
and violation.getPropertyPath()
parameters).
How can I create a ConstraintViolation
myself without having the framework do it for me via annotations (I use Hibernate Validator)?
Code example:
List<String> columnsListForSorting = new ArrayList<String>(service.getColumnsList(domain));
Collections.sort(columnsListForSorting);
String firstFieldToSortBy = this.getTranslatedFieldName(domain.getClass().getCanonicalName(), sortingInfo.getSortedColumn());
if (!columnsListForSorting.contains(firstFieldToSortBy)){
throw new ConstraintViolationException(<what here?...>);
}
Thanks.
throw new MissingFilterField(firstFieldToSortBy)
? – Yautia