public class Form<T>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
Form.Display
Defines a form element's display name.
|
static class |
Form.Field
A form field.
|
Constructor and Description |
---|
Form(java.lang.Class<T> clazz,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config)
Creates a new
Form . |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.lang.Class<?>[] groups,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config) |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.lang.Class<?> group,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config) |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.util.Map<java.lang.String,java.lang.String> data,
java.util.List<ValidationError> errors,
java.util.Optional<T> value,
java.lang.Class<?>[] groups,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config)
Creates a new
Form . |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.util.Map<java.lang.String,java.lang.String> data,
java.util.List<ValidationError> errors,
java.util.Optional<T> value,
java.lang.Class<?> group,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config) |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.util.Map<java.lang.String,java.lang.String> data,
java.util.List<ValidationError> errors,
java.util.Optional<T> value,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config) |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config) |
Modifier and Type | Method and Description |
---|---|
java.util.List<ValidationError> |
allErrors()
Deprecated.
Deprecated as of 2.7.0. Method has been renamed to
errors() . |
Form.Field |
apply(java.lang.String key)
Retrieves a field.
|
Form<T> |
bind(com.fasterxml.jackson.databind.JsonNode data,
java.lang.String... allowedFields)
Binds Json data to this form - that is, handles form submission.
|
Form<T> |
bind(java.util.Map<java.lang.String,java.lang.String> data,
java.lang.String... allowedFields)
Binds data to this form - that is, handles form submission.
|
Form<T> |
bindFromRequest(Http.Request request,
java.lang.String... allowedFields)
Binds request data to this form - that is, handles form submission.
|
Form<T> |
bindFromRequest(java.util.Map<java.lang.String,java.lang.String[]> requestData,
java.lang.String... allowedFields)
Binds request data to this form - that is, handles form submission.
|
Form<T> |
bindFromRequest(java.lang.String... allowedFields)
Binds request data to this form - that is, handles form submission.
|
protected T |
blankInstance() |
Form<T> |
discardingErrors() |
java.util.Optional<ValidationError> |
error(java.lang.String key) |
java.util.List<ValidationError> |
errors()
Returns all errors.
|
java.util.List<ValidationError> |
errors(java.lang.String key) |
com.fasterxml.jackson.databind.JsonNode |
errorsAsJson() |
com.fasterxml.jackson.databind.JsonNode |
errorsAsJson(Lang lang)
Returns the form errors serialized as Json using the given Lang.
|
Form.Field |
field(java.lang.String key)
Retrieves a field.
|
Form<T> |
fill(T value)
Populates this form with an existing value, used for edit forms.
|
T |
get()
Gets the concrete value only if the submission was a success.
|
protected java.lang.Object[] |
getArgumentsForConstraint(java.lang.String objectName,
java.lang.String field,
javax.validation.ConstraintViolation<java.lang.Object> violation) |
java.lang.Class<T> |
getBackedType() |
java.util.Optional<ValidationError> |
getError(java.lang.String key)
Deprecated.
Deprecated as of 2.7.0. Method has been renamed to
error(String) . |
java.util.Optional<ValidationError> |
getGlobalError()
Deprecated.
Deprecated as of 2.7.0. Method has been renamed to
globalError() . |
protected java.lang.String |
getMessageForConstraintViolation(javax.validation.ConstraintViolation<java.lang.Object> violation)
When dealing with @ValidateWith or @ValidatePayloadWith annotations, and message parameter is not used in
the annotation, extract the message from validator's getErrorMessageKey() method
|
java.util.Optional<ValidationError> |
globalError()
Retrieves the first global error (an error without any key), if it exists.
|
java.util.List<ValidationError> |
globalErrors()
Retrieve all global errors - errors without a key.
|
boolean |
hasErrors() |
boolean |
hasGlobalErrors() |
java.lang.String |
name() |
java.util.Map<java.lang.String,java.lang.String> |
rawData() |
protected java.util.Map<java.lang.String,java.lang.String> |
requestData(Http.Request request) |
java.lang.String |
toString() |
java.util.Optional<T> |
value() |
Form<T> |
withError(java.lang.String key,
java.lang.String error) |
Form<T> |
withError(java.lang.String key,
java.lang.String error,
java.util.List<java.lang.Object> args) |
Form<T> |
withError(ValidationError error) |
Form<T> |
withGlobalError(java.lang.String error) |
Form<T> |
withGlobalError(java.lang.String error,
java.util.List<java.lang.Object> args) |
public Form(java.lang.Class<T> clazz, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
Form
. Consider using a FormFactory
rather than this constructor.clazz
- wrapped classmessagesApi
- messagesApi component.formatters
- formatters component.validatorFactory
- validatorFactory component.config
- config component.public Form(java.lang.String rootName, java.lang.Class<T> clazz, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.lang.Class<?> group, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.lang.Class<?>[] groups, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.util.Map<java.lang.String,java.lang.String> data, java.util.List<ValidationError> errors, java.util.Optional<T> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.util.Map<java.lang.String,java.lang.String> data, java.util.List<ValidationError> errors, java.util.Optional<T> value, java.lang.Class<?> group, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.util.Map<java.lang.String,java.lang.String> data, java.util.List<ValidationError> errors, java.util.Optional<T> value, java.lang.Class<?>[] groups, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
Form
. Consider using a FormFactory
rather than this constructor.rootName
- the root name.clazz
- wrapped classdata
- the current form data (used to display the form)errors
- the collection of errors associated with this formvalue
- optional concrete value of type T
if the form submission was successfulgroups
- the array of classes with the groups.messagesApi
- needed to look up various messagesformatters
- used for parsing and printing form fieldsvalidatorFactory
- the validatorFactory component.config
- the config component.public java.lang.Class<T> getBackedType()
protected T blankInstance()
protected java.util.Map<java.lang.String,java.lang.String> requestData(Http.Request request)
public Form<T> bindFromRequest(java.lang.String... allowedFields)
allowedFields
- the fields that should be bound to the form, all fields if not specified.public Form<T> bindFromRequest(Http.Request request, java.lang.String... allowedFields)
request
- the request to bind data from.allowedFields
- the fields that should be bound to the form, all fields if not specified.public Form<T> bindFromRequest(java.util.Map<java.lang.String,java.lang.String[]> requestData, java.lang.String... allowedFields)
requestData
- the map of data to bind fromallowedFields
- the fields that should be bound to the form, all fields if not specified.public Form<T> bind(com.fasterxml.jackson.databind.JsonNode data, java.lang.String... allowedFields)
data
- data to submitallowedFields
- the fields that should be bound to the form, all fields if not specified.protected java.lang.Object[] getArgumentsForConstraint(java.lang.String objectName, java.lang.String field, javax.validation.ConstraintViolation<java.lang.Object> violation)
protected java.lang.String getMessageForConstraintViolation(javax.validation.ConstraintViolation<java.lang.Object> violation)
violation
- the constraint violation.public Form<T> bind(java.util.Map<java.lang.String,java.lang.String> data, java.lang.String... allowedFields)
data
- data to submitallowedFields
- the fields that should be bound to the form, all fields if not specified.public java.util.Map<java.lang.String,java.lang.String> rawData()
public java.lang.String name()
public java.util.Optional<T> value()
public Form<T> fill(T value)
value
- existing value of type T
used to fill this formpublic boolean hasErrors()
true
if there are any errors related to this form.public boolean hasGlobalErrors()
true
if there any global errors related to this form.public java.util.List<ValidationError> globalErrors()
@Deprecated public java.util.Optional<ValidationError> getGlobalError()
globalError()
.public java.util.Optional<ValidationError> globalError()
@Deprecated public java.util.List<ValidationError> allErrors()
errors()
.public java.util.List<ValidationError> errors()
public java.util.List<ValidationError> errors(java.lang.String key)
key
- the field name associated with the error.@Deprecated public java.util.Optional<ValidationError> getError(java.lang.String key)
error(String)
.key
- the field name associated with the error.public java.util.Optional<ValidationError> error(java.lang.String key)
key
- the field name associated with the error.public com.fasterxml.jackson.databind.JsonNode errorsAsJson()
public com.fasterxml.jackson.databind.JsonNode errorsAsJson(Lang lang)
lang
- the language to use.public T get()
value()
instead.java.lang.IllegalStateException
- if there are errors binding the form, including the errors as JSON in the messagepublic Form<T> withError(ValidationError error)
error
- the ValidationError
to add to the returned form.public Form<T> withError(java.lang.String key, java.lang.String error, java.util.List<java.lang.Object> args)
key
- the error keyerror
- the error messageargs
- the error argumentspublic Form<T> withError(java.lang.String key, java.lang.String error)
key
- the error keyerror
- the error messagepublic Form<T> withGlobalError(java.lang.String error, java.util.List<java.lang.Object> args)
error
- the global error messageargs
- the global error argumentspublic Form<T> withGlobalError(java.lang.String error)
error
- the global error messagepublic Form<T> discardingErrors()
public Form.Field apply(java.lang.String key)
key
- field namepublic Form.Field field(java.lang.String key)
key
- field namepublic java.lang.String toString()
toString
in class java.lang.Object