[bv-dev] Ordered Validation (practically)
Emmanuel Bernard
emmanuel at hibernate.org
Fri Jan 6 05:11:40 EST 2012
On 5 janv. 2012, at 21:53, Cemo wrote:
>
>
> With my proposal you need to define A interfaces instead of AxMxN - A being the number of separate phases in validation - and reuse the same set of interfaces for all your classes and all your fields in a given project.
>
>> @GroupSequence(value={Cheap.class,Expensive.class}, ordering=PER_TARGET)
>> public class DomainObject {
>>
>> @Size(max=50, groups=Cheap.class) // constraint 1a
>> @Pattern(regexp="[a-z]*", groups=Expensive.class) // constraint 1b
>> private String name;
>>
>> @Size(max=20, groups=Cheap.class) // constraint 2a
>> @URL(groups=Expensive.class) // constraint 2b
>> private String email;
>>
>> @Size(max=100, groups=Cheap.class) // constraint 3a
>> @Pattern(regexp="[0-9]*", groups=Expensive.class) // constraint 3b
>> private String password;
>> }
>
> From my understanding, if there is violation at size constraint of name field, email or passworld would not be validated? What I need is I want to validate all fields but for each field I would like to raise at most one violation an ordered way. For example, first size than pattern for name field.
No, no, in my proposal, @GroupSequence.ordering=PER_TARGET means that this group sequence is applied per field and not globally. This is the behavior you are describing. For example, BV could return the following failures:
- name: size beyond 50
- email: not a url
- password: too long
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/beanvalidation-dev/attachments/20120106/98be2961/attachment-0001.html
More information about the beanvalidation-dev
mailing list