Hi,
Honestly I am trying to learn validation framework and sometimes because of my poor english I have difficulties in order to express myself.
hardy.ferentschik wrote:
hy are you just not defining a group sequence for your credit card checks?
I have tried your recommandation. I have another question regarding it.
Code:
public class AccountBean {
@NotEmpty(groups = OrderChecks.class, message = "{xxx.account.cc}")
@IsBannedCard(groups = OrderChecks.class, message = "{xxx.constraints.bannedCCNumber}")
@IsValidCardNumber(groups = OrderChecks.class, message = "{xxx.account.invalidCardNumber}")
private String creditCart;
@NotEmpty(groups = OrderChecks.class, message = "{xxx.account.ccVal}")
private String cc;
@NotEmpty(groups = PersonalChecks.class, message = "{xxx.account.userId}")
private String userId
}
Can you help me to implement such a validation? Note that I have just added another field "cc".
For the proposal part (maybe proposal is not good word :) ),
I had just wanted to has a single error message for compound constraints. For my requirement neither displaying error composing constraint itself nor all messages from sub constraint are necessary for me. It is nice to have only first violated constraint message. With delegated I wanted to express it.
If a validated property is null, it should not show @Size error message too. Displaying only notNull message is what I want.
Code:
@Documented
@NotNull
@Size(min=1)
@ReportAsSingleViolation
@Constraint(validatedBy = NotEmpty.NotEmptyValidator.class)
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
public @interface NotEmpty {}
Another solution which came to my mind is adding a new annotation for such kind of usages.
Maybe @ValidateUntilViolation ? It is clearer than for having different many interfaces.
Code:
@ValidateUntilViolation
@NotEmpty(groups = OrderChecks.class, message = "{xxx.account.cc}")
@IsBannedCard(groups = OrderChecks.class, message = "{xxx.constraints.bannedCCNumber}")
@IsValidCardNumber(groups = OrderChecks.class, message = "{xxx.account.invalidCardNumber}")
private String creditCart;
Maybe what I have written does not make sense. Please forgive my ignorance.
Thanks