12. Example 09B – Model Validation
The following application is a variation of the previous one. Previously, for action A:
- the validation rules file was named A-validation.xml
- the validation error messages file was named A.properties
Here, for action A of model M:
- the validation rules file is named M-validation.xml
- the validation error messages file is named M.properties
- The A-validation.xml file still exists, but its contents redirect the validation rules to the M-validation.xml file.
These are the only changes we will make to the previous version.
The NetBeans project is as follows:
![]() |
- in [1], the [FormInt] action and its validation file
- in [2], its model [FormIntModel], the validation file for this model, and the messages associated with this model.
Everything else is identical to the previous version.
The [FormInt-validation.xml] file is as follows:
<!--
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//
EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
-->
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//
EN" "http://localhost:8084/exemple-09B/example/xwork-validator-1.0.2.dtd">
<validators>
<field name="model" >
<field-validator type="visitor">
<param name="appendPrefix">false</param>
<message/>
</field-validator>
</field>
</validators>
We won’t attempt to explain the contents of this file. We’ll take it at face value, keeping in mind its purpose: to delegate validation rules to the model. You might wonder what this is for. In fact, the model, its validation rules, and its messages may already exist and be used by different actions. Rather than repeating the same validation rules and messages for different actions, it is better to delegate these functionalities to the model.
The [FormIntModel-validation.xml] file is identical to the [FormInt-validation.xml] file from the previous version.
The [FormIntModel.properties] file is identical to the [FormInt.properties] file from the previous version.
Readers are invited to test this new version.
