[bv-dev] Ordered Validation (practically)
Gerhard Petracek
gerhard.petracek at gmail.com
Tue Jan 3 16:12:05 EST 2012
hi,
actually we had a related discussion about it for bv v1.0.
(the topic was "sort-circuit" and one suggestion was to introduce e.g.
ValidatorContext#failAtFirstViolation)
+1 for re-visiting this topic.
regards,
gerhard
2012/1/3 Cemo <cemalettin.koc at gmail.com>
> Hi experts,
>
> After reading your comments and mail list I realized that it will be
> better share our opinions here about our problems.
>
> First, I would like to thanks all of you to provide such
> an elegant library and spec. After latest improvements at spring side, I am
> sure that bean validation will be defacto validation framework among java
> community.
>
> The only problem We are facing is that ordered validations.
>
> In a common sense validation such this can be feasible:
>
> public class AccountBean {
>>
>> @CheapValidation(groups=Name1.class)
>> @ExpensiveValidation(groups=Name2.class)
>> @VeryExpensiveValidation(groups=Name3.class)
>> String name;
>>
>> @CheapValidation(groups=Surname1.class)
>> @ExpensiveValidation(groups=Surname2.class)
>> @VeryExpensiveValidation(groups=Surname3.class)
>> String surname;
>>
>> public interface Name1 {}
>> public interface Name2 {}
>> public interface Name3 {}
>> @GroupSequence({Name1.class, Name2.class, Name3.class})
>> public interface Name {}
>>
>> public interface Surname1 {}
>> public interface Surname2 {}
>> public interface Surname3 {}
>> @GroupSequence({Surname1.class, Surname2.class, Surname3.class})
>> public interface Surname {}
>> }
>>
>>
>
> There is two common usage for this. The first usage: some validations are
> expensive that should be runned if all validations pass. Another usage is
> for each field there should be one violation. For email, if it is empty,
> uniqueEmail constraint must not be checked. I hope that how much necessary
> it is for us you can imagine. Almost all fields has such restrictions.
> Ordering and shortcutting are crucial for us.
>
> But just to provide validation order and shortcut GroupSequence is
> practically impossible to use at enterprice level. For each field again
> and again we are declaring interfaces. It is not only intuitive but also
> seems ugly. By the way what is came to my mind is for each constraint,
> declaring a order like this:
>
> public class AccountBean {
>>
>> @CheapValidation(order=0,groups=Name1.class)
>> @ExpensiveValidation(order=1,groups=Name2.class)
>> @VeryExpensiveValidation(order=2,groups=Name3.class)
>> String name;
>>
>> @CheapValidation(order=0,groups=Surname1.class)
>> @ExpensiveValidation(order=1,groups=Surname2.class)
>> @VeryExpensiveValidation(order=2,groups=Surname3.class)
>> String surname;
>> }
>>
>>
> Default value for ordering might be same for all constraints.
>
> Please help community. :)
>
> Thanks & happy new year
>
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/beanvalidation-dev/attachments/20120103/43e90f59/attachment.html
More information about the beanvalidation-dev
mailing list