May 2010

What's inside a violation?

What's Inside A Violation?

If the validator found a number of violations, what can we do with it? Let's have a look at the simple usages of violation objects.

Validate single, primitive attribute

Learning Test One: Validate a single, primitive attribute

Time to write our first (domain) object and validate something. We'll do this using the TestNG framework to create a tiny test driver showcasing how the most basic validation API calls interact.

Ansgar's Sandbox

package abc;
public class Xy {
  private String name;
  private int length;

  public Xy() {
    // ...
  }
}

Basic Project Setup

Basic Project Setup

I'll use Apache Maven 2.x and IntelliJ IDEA as my primary development tools, so you might want to learn how to use these first if you plan to work through the examples for yourself. All source code and project files for this walkthrough is available from github using

git://github.com/ansgarkonermann/bean-validation-with-jsr303.git

as clone URL.

JSR 303 Walkthrough

Seems as if JSR 303 "Bean Validation" specification has been around for a while now. At least long enough to have a look for myself. Curious to learn both the possibilities and the limits of current implementations, I'll simply try out the reference implementation and explain what I'm doing in a step-by step manner.