Before you start with Play forms, read the documentation on the Play enhancer. The Play enhancer generates accessors for fields in Java classes for you, so that you don’t have to generate them yourself. You may decide to use this as a convenience. All the examples below show manually writing accessors for your classes.

The play.data package contains several helpers to handle HTTP form data submission and validation. The easiest way to handle a form submission is to define a play.data.Form that wraps an existing class:

The validate-method can return the following types: String, List<ValidationError> or Map<String,List<ValidationError>>

validate method is called after checking annotation-based constraints and only if they pass. If validation passes you must return null or an empty list. Returning any other non-null value (including empty string) is treated as failed validation.

List<ValidationError> may be useful when you have additional validations for fields. For example:

In case you want to define a mapping from a custom object to a form field string and vice versa you need to register a new Formatter for this object.You can achieve this by registering a provider for Formatters which will do the proper initialization.For an object like JodaTime’s LocalTime it could look like this: