Skip to content

v0.7.2 Documentation

cduplichien edited this page Feb 17, 2013 · 26 revisions

Springjutsu Validation v0.7.2 Documentation & Reference Guide

What is Springjutsu Validation

Springjutsu Validation replaces standard JSR-303 validation annotations with robust XML validation definitions offering several possibilities not found in a standard bean validation library:

  • Simple creation and definition of custom validation rules
  • Options for form-specific contextual validation within Spring MVC and Spring Web Flow
  • Conditional execution of validation rules based on the outcome of another rule
  • Encapsulation of common patterns of multiple rules into reusable templates
  • Programmatic access to request parameters and other request data through Expression Language
  • Full i8n internationalization support by loading error messages and field labels from a spring message source
  • Easily apply validation rules and conditional validation to members of collections.

In Springjutsu Validation all validation is comprised of combinations of rules.

<!-- A rule looks like this. -->
<rule path="address.zipCode" type="exactLength" value="5"/>

As you might guess, the above rule constrains a field named "zipCode" found on a sub-bean field named "address" to be exactly 5 characters long.

When a rule fails error messages are created by looking up message codes from a spring MessageSource using conventions which can be specified within the configuration options (next section). This error message is registered as a field error on the standard Spring Errors object.

Let's assume that the address bean was of type org.mycompany.coolproject.model.PostalAddress in our project. Let's also assume we have the following message properties defined:

# look up error messages - errors.<rule type>
errors.exactLength={0} must be exactly {1} characters long.
# look up field labels - <simple class name>.<field name>
postalAddress.zipCode=Postal Code

Springjutsu Validation fills in the message args, and the generated error message is:

Postal Code must be exactly 5 characters long.

This is usage at its most basic. But, before looking at more advanced usage we'll cover how to acquire Springjutsu Validation and configure it for use within your application.

Dependencies & Configuration

About Validation Rules

Prepackaged Rules

Defining Custom Rules

Writing a Rules XML

Basic Validation

Validating Forms & Web Flow States

Conditional Validation

Validating Collection Members

Validation Templates

Sub Classes & Validation Inheritance

Using Expression Language

Handling Validation Success & Failure

Clone this wiki locally