In Struts 2 we can develop @CustomValidator
which can be used in application wide
@CustomValidator(type = "CustomerNumberValidator", fieldName = "customerNo")
For validation more than one field we use @ExpressionValidator
@ExpressionValidator(expression =
"( (!''.equals(account.firstName) && (!''.equals(account.lastName) )
|| (presonalAccount == false)",
key = "validate.account.name")
If the expression is too complicated and needs to work on more than one field we use OGNL to call the static method. The static method will do the validation and return a boolean
for example
@ExpressionValidator(expression = "@foo.bar.CalendarUtil@compareDates(fromDate,toDate)", key = "validate.date.before")
Above is some how a Custom Expression Validator !
And we use @foo.bar.CalendarUtil@compareDates
in application wide to make this validation for us.
Is there another approach which enables us to use a custom wide validator?!
Is there any custom expression validator which can be added to Struts and we can call it in Action
in the way we use @CustomValidator
?
compareDatesValidator
and set it inaddActionError
– Tessy