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.Validator validator)
Creates a new
Form . |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.lang.Class<?>[] groups,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.lang.Class<?> group,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
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.Validator validator)
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.Validator validator) |
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.Validator validator) |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.util.Map<java.lang.String,java.lang.String> data,
java.util.Map<java.lang.String,java.util.List<ValidationError>> errors,
java.util.Optional<T> value,
java.lang.Class<?>[] groups,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator)
Deprecated.
Deprecated as of 2.6.0. Replace the parameter
Map<String,List<ValidationError>> with a simple List<ValidationError> . |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.util.Map<java.lang.String,java.lang.String> data,
java.util.Map<java.lang.String,java.util.List<ValidationError>> errors,
java.util.Optional<T> value,
java.lang.Class<?> group,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator)
Deprecated.
Deprecated as of 2.6.0. Replace the parameter
Map<String,List<ValidationError>> with a simple List<ValidationError> . |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
java.util.Map<java.lang.String,java.lang.String> data,
java.util.Map<java.lang.String,java.util.List<ValidationError>> errors,
java.util.Optional<T> value,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator)
Deprecated.
Deprecated as of 2.6.0. Replace the parameter
Map<String,List<ValidationError>> with a simple List<ValidationError> . |
Form(java.lang.String rootName,
java.lang.Class<T> clazz,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
Modifier and Type | Method and Description |
---|---|
java.util.List<ValidationError> |
allErrors()
Returns all 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() |
java.util.Map<java.lang.String,java.lang.String> |
data()
Deprecated.
Deprecated as of 2.6.0. Use
rawData() instead which returns an unmodifiable map. |
void |
discardErrors()
Deprecated.
Deprecated as of 2.6.0. Use
discardingErrors() instead. |
Form<T> |
discardingErrors() |
ValidationError |
error(java.lang.String key)
Deprecated.
Deprecated as of 2.6.0. Use
getError(String) instead. |
java.util.Map<java.lang.String,java.util.List<ValidationError>> |
errors()
Deprecated.
Deprecated as of 2.6.0. Use
allErrors() instead. |
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.metadata.ConstraintDescriptor<?> descriptor) |
java.lang.Class<T> |
getBackedType() |
java.util.Optional<ValidationError> |
getError(java.lang.String key) |
java.util.Optional<ValidationError> |
getGlobalError()
Retrieves the first global error (an error without any key), if it exists.
|
protected java.lang.String |
getMessageForConstraintViolation(javax.validation.ConstraintViolation<java.lang.Object> violation)
When dealing with @ValidateWith annotations, and message parameter is not used in
the annotation, extract the message from validator's getErrorMessageKey() method
|
ValidationError |
globalError()
Deprecated.
Deprecated as of 2.6.0. Use
getGlobalError() instead. |
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() |
void |
reject(java.lang.String error)
Deprecated.
Deprecated as of 2.6.0. Use
withGlobalError(String) instead. |
void |
reject(java.lang.String error,
java.util.List<java.lang.Object> args)
Deprecated.
Deprecated as of 2.6.0. Use
withGlobalError(String, List) instead. |
void |
reject(java.lang.String key,
java.lang.String error)
Deprecated.
Deprecated as of 2.6.0. Use
withError(String, String) instead. |
void |
reject(java.lang.String key,
java.lang.String error,
java.util.List<java.lang.Object> args)
Deprecated.
Deprecated as of 2.6.0. Use
withError(String, String, List) instead. |
void |
reject(ValidationError error)
Deprecated.
Deprecated as of 2.6.0. Use
withError(ValidationError) instead. |
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.Validator validator)
Form
. Consider using a FormFactory
rather than this constructor.clazz
- wrapped classmessagesApi
- messagesApi component.formatters
- formatters component.validator
- validator component.public Form(java.lang.String rootName, java.lang.Class<T> clazz, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.lang.Class<?> group, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.lang.Class<?>[] groups, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
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.Validator validator)
@Deprecated public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.util.Map<java.lang.String,java.lang.String> data, java.util.Map<java.lang.String,java.util.List<ValidationError>> errors, java.util.Optional<T> value, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
Map<String,List<ValidationError>>
with a simple List<ValidationError>
.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 successfulmessagesApi
- needed to look up various messagesformatters
- used for parsing and printing form fieldsvalidator
- the validator component.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.Validator validator)
@Deprecated public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.util.Map<java.lang.String,java.lang.String> data, java.util.Map<java.lang.String,java.util.List<ValidationError>> errors, java.util.Optional<T> value, java.lang.Class<?> group, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
Map<String,List<ValidationError>>
with a simple List<ValidationError>
.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 successfulgroup
- the class with the group.messagesApi
- needed to look up various messagesformatters
- used for parsing and printing form fieldsvalidator
- the validator component.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.Validator validator)
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 fieldsvalidator
- the validator component.@Deprecated public Form(java.lang.String rootName, java.lang.Class<T> clazz, java.util.Map<java.lang.String,java.lang.String> data, java.util.Map<java.lang.String,java.util.List<ValidationError>> errors, java.util.Optional<T> value, java.lang.Class<?>[] groups, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
Map<String,List<ValidationError>>
with a simple List<ValidationError>
.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 fieldsvalidator
- the validator 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.metadata.ConstraintDescriptor<?> descriptor)
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.@Deprecated public java.util.Map<java.lang.String,java.lang.String> data()
rawData()
instead which returns an unmodifiable map.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 ValidationError globalError()
getGlobalError()
instead.null
.public java.util.Optional<ValidationError> getGlobalError()
@Deprecated public java.util.Map<java.lang.String,java.util.List<ValidationError>> errors()
allErrors()
instead.public java.util.List<ValidationError> allErrors()
public java.util.List<ValidationError> errors(java.lang.String key)
key
- the field name associated with the error.@Deprecated public ValidationError error(java.lang.String key)
getError(String)
instead.key
- the field name associated with the error.public java.util.Optional<ValidationError> getError(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 message@Deprecated public void reject(ValidationError error)
withError(ValidationError)
instead.error
- the ValidationError
to add.public Form<T> withError(ValidationError error)
error
- the ValidationError
to add to the returned form.@Deprecated public void reject(java.lang.String key, java.lang.String error, java.util.List<java.lang.Object> args)
withError(String, String, List)
instead.key
- the error keyerror
- the error messageargs
- the error argumentspublic 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 arguments@Deprecated public void reject(java.lang.String key, java.lang.String error)
withError(String, String)
instead.key
- the error keyerror
- the error messagepublic Form<T> withError(java.lang.String key, java.lang.String error)
key
- the error keyerror
- the error message@Deprecated public void reject(java.lang.String error, java.util.List<java.lang.Object> args)
withGlobalError(String, List)
instead.error
- the error messageargs
- the error argumentspublic Form<T> withGlobalError(java.lang.String error, java.util.List<java.lang.Object> args)
error
- the global error messageargs
- the global error arguments@Deprecated public void reject(java.lang.String error)
withGlobalError(String)
instead.error
- the error message.public Form<T> withGlobalError(java.lang.String error)
error
- the global error message@Deprecated public void discardErrors()
discardingErrors()
instead.public 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