Hi there-
I am trying to figure out a way to explicitly call individual methods annotated with AssertTrue as opposed to all at once via the ClassValidator. A little background...
I have an entity with several methods annotated with AssertTrueto perform complex validation (validates multiple fields). My web app plays nicely with this since I manually call Hibernate Validation from my own custom EntityHome interceptor on page actions.
From my HomeInterceptor.java:
@AroundInvoke
public Object aroundInvoke(InvocationContext ctx) throws Exception {
// Only validate if the annotation is there...
if (!ctx.getMethod().isAnnotationPresent(ValidatableAction.class)) {
return ctx.proceed();
}
Object instance = ((Home<?, ?>) ctx.getTarget()).getInstance();
ClassValidator<Object> validator = Validators.instance().getValidator(
instance);
InvalidValue[] ivs = validator.getInvalidValues(instance);
if (ivs.length > 0) {
for (InvalidValue invalidValue : ivs) {
FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR,
invalidValue.getMessage());
}
return null;
}
return ctx.proceed();
}When this code executes, it validates all the methods annotated with AssertTrue. While that is good, what I really would like is to explicitly call certain methods annotated with AssertTrue.
The reason I would like to do this is that during my page-flow, the user is entering attributes to the entity page-by-page and I would like to call the relevant AssertTrue method for each page. In short, partial object validation.
Thanks in advance for your help!
D