Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: how to specify sequence on compound constraints
PostPosted: Mon Feb 10, 2014 10:55 pm 
Newbie

Joined: Wed Mar 14, 2007 4:16 am
Posts: 1
Hi,

I have a clarification with configuring bean validation for one scenario. Below is my compound constraint

Code:
@Target({ FIELD })
@Retention(RUNTIME)
@Constraint(validatedBy = { EmpIdValidator.class })
@NotNull(message = "Id cannot be null")
@Range(min = 0, max = 99, message = "Invalid EmpId Range")
public @interface ValidEmpId {

  String message() default "Id does not exits";

  Class<?>[] groups() default {};

  Class<? extends Payload>[] payload() default {};
}


Code:
EmpValidator.isValid method
  public boolean isValid(final Long id,
      final ConstraintValidatorContext validatorContext) {
    // query db and check the validity, for now just do plain validation
    if ((id != null) && (id > 20) && (id < 80)) {
      return true;
    }
    return false;
  }


when i tested this setup, my bean is getting validated properly but the sequence is getting changed everytime,
- it is getting validated with both Range and EmpIdValidator above valid method interchanging.

How do I specify this in a proper sequence so that the validation occur in this order.
- NotNull
- Range
- EmpIdValidator

I am able to execute order properly this if I don't create compound constraint and directly specify the validations on the field directly, but I am supposed to re-use this validations in many pages. So, the only solution for me is to use compound constraint.

Can you please suggest how do I specify the sequence on above ValidEmpId to get problem solved?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.