Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this example, when firstAndLast() is executed, the fields firstName and lastName will be validated. When middle() is executed, only middleName will be validated. When a method is annotated with the Profiles annotation, only the validations in the specified profiles will be performed.

Internationalization of messages

The OVal annotations (and corresponding XML tags) have a message attribute that can be used to specify either the error message, or the key of the error message. If a key is found in a property file, matching the value of the massage attribute, it will be used as the message, otherwise the value will be used as a literal string. For example, given this property file:

Code Block
titleBookAction.properties

notnull.field=${field.name} cannot be null

and this class:

Code Block
titleBookAction.java

public class BookActionextends ActionSupport {
    @NotNull(message = "notnull.field")
    private String title;

    @NotNull(message = "You must enter a valid ISBN")
    private String isbn;
...
}

When that action is validated, the field errors would be:

  • "title cannot be null"
  • "You must enter a valid ISBN"

The current OVal "context" object is pushed into the stack for each validator, so it can be accessed from the property file to build the error message. See the OVal javadoc for more properties available in the FieldContext class.

The OVal Validation Interceptor

...