0

I have the following model class

 public class ContactDetail {
     @NotNull(message="StartNum cannot be null")
     private int startNum;
     @NotNull(message="EndNum cannot be null")
     private int endNum; }

How would I go about validating the range size for these fields? I have tried adding

public int maxRangeSize=1000;

@AssertTrue(message="Range size is invalid" )
public boolean isRangeValid(){

Integer rangeSize= endNum-startNum;

if(rangeSize < 0 || rangeSize >= maxRangeSize)
{
    return false;
}
return true;

}

but I would like to know if there is a way to show in the validation failure message which startnum and endnum or even whats the set maxrangesize, so the error will be useful to the user?

obsessiveCookie
  • 1,130
  • 2
  • 18
  • 33

1 Answers1

0

try this example:

@Digits(integer = 3, fraction = 0, message = "The value of age can not be more than 3 digits")
@Range(min = 10, max = 150)
private int age;
Moe
  • 2,672
  • 10
  • 22