Java applications which use Jargus have a collection of reusable Validator classes available. But there is always the need to implement a ValidationHandler in an appropriate manner to receive an application dependend output. It is especially cumbersome for jsp applications to implement this interface as it limits the advantages offered by jsp scripting capabilities.
The use of XMLValidator class can overcome this problem. Instead of implementing the ValidationHandler interface an application developer creates an xml configuration file which describes the output that should be displayed if an error in the validation process occurs. This example describes how to create an xml file and how to use the XMLValidationHandler in a java application. For usage in a jsp application please refer to XML-JSP example.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- example of a XMLValidationHandler configuration file.
More information can be found in javadoc api doc of XMLValidationHandler
class.
-->
<jargus>
Define a mapping between parameter names and a label which can be displayed in an error message instead. It's not always wanted to display the parameter name in an error message. To display a userfriendly error message actual parameters have to be mapped to labels.
<mapping parameter="p1" label="Name"/>
<mapping parameter="p2" label="E-Mail" />
With the ExtendValidationHandler.getMessage()
you can retrieve a summary error message. This error message will start with the string set here.
<error-message>Please type in:</error-message>
Set a error message for every kind of validation.
<check validation="exist">
<error-message>${parameter} has to be inserted.</error-message>
</check>
<check validation="contains">
<error-message>${parameter} must contain ${arguments}.</error-message>
</check>
</jargus>