JDistil

Validation

The JDistil framework performs validation for each request submitted to the servlet controller. Specifically, the servlet controller delegates validation to a validation processor before invoking any processors configured for a submitted action. The "com.bws.jdistil.core.validation.DefaultValidator" framework processor class is used by default but can be overridden by specifying an application defined validator factory class in the application specific "core.properties" file. The custom factory class must implement IFactory interface and instances provided by the factory must implement the IProcessor interface.

The default framework processor class supporting action validation uses configuration data associated with the submitted action to perform validation. Specifically, the processor uses the configuration manager to retrieve an action reference using the submitted action ID. This action reference may contain one or more action rules supporting action level validation and may contain one or more field rules supporting field level validation. These rules are defined in the application specific configuration data and the processor delegates processing to these rules to perform the actual validation. These rules are also responsible for populating an error messages collection provided by the processor when validation fails. The error messages are included in a process context allowing them to be referenced and displayed by an application view.

Action Rules

The following documents the "com.bws.jdistil.core.validation.rules.IActionRule" interface. This interface is implemented by classes used to perform action level validation.
public interface IActionRule {

    public boolean isValid(String actionId, Map<String, String[]> data, Locale locale, List<String> messages);

}
				
Class Description
AtLeastOneFieldRule Validates a field value exists for at least one of multiple specified fields.

Field Rules

The following documents the "com.bws.jdistil.core.validation.rules.IFieldRule" interface. This interface is implemented by classes used to perform field level validation. The framework provides several field rule classes which are documented in the table below.
public interface IFieldRule {

    public boolean isValid(String id, String value, Locale locale, List<String> messages);

}
				
Class Description
ConverterRule Validates a field value using the field specific converter class defined in the application configuration.
RegularExpressionRule Validates a field value conforms to a defined regular expression. This class can be used directly or extended to provide a specific field rule.
NumberRule Validates a field value conforms to a valid number. This rule supports maximum precision and scale and restrictions on positive and negative values. These specifics are defined when the rule instance is created.
EmailRule Validates a field value conforms to a valid email address.
PhoneNumberRule Validates a field value conforms to a valid phone number.
PostalCodeRule Validates a field value conforms to a valid postal code.
MaxLengthRule Validates a field value does not exceed the maximum number of characters defined for a text area.

Validator Factory

An application's validator is accessible using the "com.bws.jdistil.core.validation.ValidatorFactory" class. This class returns an instance of the application specific validator factory if the class is defined in the "core.properties" file or an instance of a singleton pojo factory supporting access to the "com.bws.jdistil.core.validation.DefaultValidator" if no class is defined. The following excerpt provides an example using an application specific validator factory.
# Validator factory class name
validator.factory=org.test.validation.CustomValidatorFactory