In struts 2, we can develop @CustomValidator , which can be used in widespread use.
@CustomValidator(type = "CustomerNumberValidator", fieldName = "customerNo")
For checking 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 complex and should work on MORE THAN ONE FIELD, we use OGNL to call the static method. The static method will check and return a boolean for example
@ExpressionValidator(expression = "@foo.bar.CalendarUtil@compareDates(fromDate,toDate)", key = "validate.date.before")
Above is an example of how a Custom Expression Validation Tool! And we use @foo.bar.CalendarUtil@compareDates in the application to do this check for us.
Is there any other approach that allows you to use a custom wide validator ?! Is there any custom expression checking mechanism that can be added to struts and we can call it in action like we use @CustomValidator
java validation struts2 struts-validation struts2-convention-plugin
Alireza Fattahi Jan 20 '15 at 6:12 2015-01-20 06:12
source share