Struts 2 Validation by Bundled Validators
Struts 2 validation framework gives many inherent validators otherwise called packaged validators for email, string, int, twofold, url, date and so on
So, we don't have to give unequivocal rationale to email, twofold, url and so forth. For giving explicit validation rationale, we can utilize regex, which we will see later.
It performs validation against the predefined validation guidelines and includes the field-level and activity level mistake messages.
It works related to the work process interceptor to show the blunder messages.
There is no parameter characterized for this interceptor.
Advantage of Bundled validators
fast development in light of the fact that we don't have to indicate the normal validators, for example, email date, string length etc.
Struts 2 provides following bundled validators.
- requiredstring validator
- stringlength validator
- email validator
- date validator
- int validator
- double validator
- url validator
- regex validator
Two approaches to utilize packaged validators
There are two different ways to utilize packaged validators:
- Plain-Validator (non-field validator) Syntax
- Field-Validator Syntax
In the following page we will see the full case of packaged validators. We should now comprehend the contrast between plain-validator linguistic structure and field-validator syntax.
Plain-Validator (non-field validator) Syntax
Plain-validator grammar can be utilized for activity level validator. In such case, a solitary validator can be connected to numerous fields.
But disservice of this methodology is we can't have any significant bearing numerous validators to single field.
Let's see straightforward case of plain-validator.
The field-validator sentence structure can be utilized for field level validator. In such case, various validator can be connected to one field. For instance, we can apply required and email validators on email field. In addition, each field can show diverse messages.
But disservice of this methodology is we can't matter regular validator to many field like plain-validator.
Let's see straightforward case of field-validator.
Which validator punctuation is better?
It is prescribed to utilize field validator by apache swaggers since it gives more flexibility.