For instance, I have a field to enter telephone number and i want it to be validated. I.e. check if the value entered is numeric and check if the entered value is having 10 digits.
I achieved this by creating a validation.xml
.
But my question is How can i use the same set of validation rules(the same file) for another field? Is that possible in Struts 2?
Asked
Active
Viewed 267 times
0

Roman C
- 49,761
- 33
- 66
- 176

user2981899
- 19
- 5
-
You can create validation for domain objects and use `visitor` validator. See http://struts.apache.org/development/2.x/docs/visitor-validator.html. – Aleksandr M Nov 12 '13 at 08:49
-
Read http://stackoverflow.com/a/16131248/1654265 and http://stackoverflow.com/a/18016661/1654265 – Andrea Ligios Nov 12 '13 at 09:31
1 Answers
0
Not sure if this is what you are looking for: Create a new file called validators.xml in WEB-INF/classes and define the new validator.
<validator name="newvalidator" class="FQCN"/>
Create a class which extends FieldValidatorSupport to implement your own validation logic.
Use the new validator in validation xml files
<field-validator type="newvalidator">

Prashant P
- 23
- 5