On Jan 22, 2012, at 8:33 PM, Gunnar Morling wrote:
I'm in the middle of writing a proposal document for BVAL-241
(method
validation), which I'm planning to put up for discussion within the
next days.
Great.
One item for which I'd like to gather some feedback beforehand is
how
to trigger method validation. I think we all agree that BV itself
should only provide the API and meta-model for method validation, but
it shouldn't actually trigger a validation of method level
constraints.
What do you mean with trigger the validation. I also think that BV should not trigger
the validation. Instead AOP frameworks or similar provide an integration where
method level validation can be enabled. If enabled the framework would call
the appropriate Validator.validateMethod method.
Instead this should be task of technologies integrating the method
validation feature to decide whether a validation is needed or not and
if so delegate that validation to BV.
Right. My understanding was that if method level validation is enabled in the integrating
framework and method level annotations exist, validation gets triggered.
The following options were mentioned at some time:
#1 Use @Valid
This would be semantically wrong IMO. @Valid is only a marker for
cascaded validation, but it shouldn't cause a validation itself.
I don't even understand how @Valid could be used to "trigger" anything in
this context.
#2 Define an annotation such as @javax.validation.ValidateGroups
within BV
@ValidateGroups({Group1.class, Group2.class})
public class OrderService {
@NotNull
public Order placeOrder((a)NotNull(groups=Group1.class) @Size(min=3,
max=20) String customerCode, @NotNull Item item, @Min(1) int quantity)
{ //... }
}
What would @ValidateGroups in this case do?
#3 Don't define anything related in BV, leave that completely to
integrators
That is probably the solution I had in mind from the beginning. Seems still most
reasonable to me.
--Hardy