I was working on validation using annotation in Struts2 and i was quite surprised to see that the annotations does not have a LongRangeFieldValidator where as the validations done using xml does have a LongRangeFieldValidator
I tried different ways to get the LongRangeFieldValidor using annotations.
LongRangeFieldValidator. It showed an error because it doesn't actually exists andcom.opensymphony.xwork2.validator.validators.LongRangeFieldValidatorcannot be converted to anAnnotationtype. This was quite obvious so i switched to next.I used
IntRangeFieldValidator. I could quite use it because it was unable to do a typecasting. I thought this should have worked because docs says it is for numeric types.DoubleRangeFieldValidatorThis one also validates (and it should) non-integer values so i had to drop this.Finally I had to convert my
longfield to aStringand had to useRegexFieldValidator.
My question is why there isn't a LongRangeFieldValidator in the package com.opensymphony.xwork2.validator.annotations and what are the best practices to obtain it?
It seems they forgot to add this annotation to the core package. Just a mistake may be or so, but there is the workaround. Use a custom validator annotation
under registered validators you can find the name of the validator
long.