I’m using struts 2 & validation annotations. I need to validate a field which is required if another is true or false. I was using @RequiredStringValidator but I realized this annotation doesn’t have the expression property.
@Validations(requiredStrings =
{@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "username", message = "El Usuario es requerido",key="security.admin.user.username.required"),
@RequiredStringValidator( type = ValidatorType.SIMPLE, fieldName = "password", message = "El Password es requerido",key="security.admin.user.password.required")}...
The field to validate is “password” but it’s only required if “autoGeneratePassword” field is false.
Thanks!
For validations requiring expression evaluation don’t use Simple
RequiredStringValidationinstead you can useFieldExpressionValidatororExpressionValidatorOne way of using it:
You can use OGNL expression to do the same.