In our example we use a different validation file for every action class.
The validation file has the same name of the class, with suffix
"-validation.xml". Here is an example:
With the previous code, we have declared a field to validate. The attribute "name" is the name
of the field as declared in the html form.
We have defined the requiredstring validation: a non blank string must be returned by the web
page. Note how we create the error message: it is a concatenation of variables.
The parameter on the getText method is a key of a properties file. In our example, the properties file is the one
associated with the class ProjectAction; the full name is ProjectAction.properties.
We can have more than one properties file for the same action, one for each locale (language) support from our application.
Since in the validation of Struts2 we can't localize the name of the field, every single error message is divided
in two or more parts and then is concatenated to have the entire error message localized (see the value of
The errors.required.1, test_input and errors.required.2 are defined in ProjectAction.properties.