You mean by Java reflection? Yes it can. From the DomainObject class you
can reach the GroupSequence annotation. That's how a Bean Validation
provider does it anyways.
Why do you need to access the order by the way?
Because of reflection is not useful, I wanted to offer another solution to
provide ordered validation. What I have offered I wrote at another mail,
@ConstraintSequence({
@NotEmpty(),
@IsValidBinCodeNumber(),
@IsCardBannedNumber(),
@IsValidCardNumber()
})
private String creditCard;
And your explanations were very clear to see why it is not possible.
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.
public class DomainObject {
@Size(max=50, order=1) // constraint 1a
@Pattern(regexp="[a-z]*",order=2) // constraint 1b
private String name;
@Size(max=20,order=1) // constraint 2a
@URL(order=2) // constraint 2b
private String email;
@Size(max=100, order=1) // constraint 3a
@Pattern(regexp="[0-9]*",order=2) // constraint 3b
private String password;
}
In this case all fields, name, email, password, will be validated. But only
one error will be displayed. And using integer for really is started to
seem not error prone for me. Also it can support groups which are great for
partial validation and does not break existing codes whose orders can be
thought same.
Let me to summarize why I need this. At our registration page we would like
to accept applications as early as possible. Every second at the
registration page is decreasing the probability for signing up. This is why
we need to show all errors at one time. This is not different than payment
pages.
By the way sometimes I have difficulties expressing myself because of being
not a native speaker. Please excuse me. And I will try to contribute spec
as much as I can do and I was not aware that experts are so helpful. :)
Thanks