Iam using Hibernate Validator for validation of data. I have used @Range attribute for validating a particular field.
@Range(min=0,max=100)
private String amount;
This is fine but can i dynamically change the values of min and max instead of hard coding. I mean can i do something like:
@Range(min=${},max=${})
private String amount;
Annotations in Java uses constants as parameters. You Cannot change them dynamically.
Compile constants can only be primitives and Strings.Check this link.
IF you want to make it configurable you can declare them as static final.
For Example:
private static final int MIN_RANGE = 1;
private static final int MAX_RANGE = 100;
and then assign in annotation.
@Range(min=MIN_RANGE,max=MAX_RANGE)
private String amount;
The value for annotation attribute must be a constant expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With