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.
|
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
logger |
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<?>[] groups,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config,
Lang lang)
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<?>[] groups,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.ValidatorFactory validatorFactory,
com.typesafe.config.Config config,
Lang lang,
boolean directFieldAccess)
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,
java.util.Map<java.lang.String,java.lang.String> data,
java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files,
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.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files,
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,
Lang lang)
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.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files,
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,
Lang lang,
boolean directFieldAccess)
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.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files,
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.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files,
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 |
---|---|
Form.Field |
apply(java.lang.String key)
Retrieves a field.
|
Form.Field |
apply(java.lang.String key,
Lang lang)
Retrieves a field.
|
Form<T> |
bind(Lang lang,
TypedMap attrs,
com.fasterxml.jackson.databind.JsonNode data,
long maxChars,
int maxDepth,
java.lang.String... allowedFields)
Binds Json data to this form - that is, handles form submission.
|
Form<T> |
bind(Lang lang,
TypedMap attrs,
com.fasterxml.jackson.databind.JsonNode data,
long maxChars,
java.lang.String... allowedFields)
Binds Json data to this form - that is, handles form submission.
|
Form<T> |
bind(Lang lang,
TypedMap attrs,
com.fasterxml.jackson.databind.JsonNode data,
java.lang.String... allowedFields)
Deprecated.
Deprecated as of 2.8.3. Use
bind(Lang, TypedMap, JsonNode, long,
String...) instead to specify the maximum chars that should be consumed by the flattened
form representation of the JSON. |
Form<T> |
bind(Lang lang,
TypedMap attrs,
java.util.Map<java.lang.String,java.lang.String> data,
java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files,
java.lang.String... allowedFields)
Binds data to this form - that is, handles form submission.
|
Form<T> |
bind(Lang lang,
TypedMap attrs,
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> |
bindFromRequestData(Lang lang,
TypedMap attrs,
java.util.Map<java.lang.String,java.lang.String[]> requestData,
java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> requestFileData,
java.lang.String... allowedFields)
Binds request data to this form - that is, handles form submission.
|
Form<T> |
bindFromRequestData(Lang lang,
TypedMap attrs,
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.
|
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.Field |
field(java.lang.String key,
Lang lang)
Retrieves a field.
|
java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> |
files() |
Form<T> |
fill(T value)
Populates this form with an existing value, used for edit forms.
|
protected void |
fillDataWith(java.util.Map<java.lang.String,java.lang.String> data,
java.util.Map<java.lang.String,java.lang.String[]> urlFormEncoded) |
protected <T> void |
fillDataWith(java.lang.String key,
java.util.Map<java.lang.String,T> data,
int valuesCount,
java.util.function.Function<java.lang.Integer,T> getValueByIndex) |
T |
get()
Gets the concrete value only if the submission was a success.
|
T |
get(Lang lang)
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() |
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.util.Optional<Lang> |
lang() |
protected long |
maxJsonChars()
The default maximum number of chars to support when binding a form from JSON.
|
protected int |
maxJsonDepth()
The default maximum depth of JSON objects and arrays when binding a form from JSON.
|
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) |
protected java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> |
requestFileData(Http.Request request) |
protected <A> java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> |
resolveDuplicateFilePartKeys(java.util.List<Http.MultipartFormData.FilePart<A>> fileParts) |
java.lang.String |
toString() |
java.util.Optional<T> |
value() |
Form<T> |
withDirectFieldAccess(boolean directFieldAccess)
Sets if during binding fields of the form should be accessed directly or via getters.
|
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) |
Form<T> |
withLang(Lang lang)
A copy of this form with the given lang set which is used for formatting when retrieving a
field (via
field(String) or apply(String) ) and for translations in errorsAsJson() . |
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.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files, 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.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files, 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 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,Http.MultipartFormData.FilePart<?>> files, 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)files
- the current form file dataerrors
- 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 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, Lang lang)
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.lang
- used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
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,Http.MultipartFormData.FilePart<?>> files, 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, Lang lang)
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)files
- the current form file dataerrors
- 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.lang
- used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
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, Lang lang, boolean directFieldAccess)
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.lang
- used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
directFieldAccess
- access fields of form directly during binding instead of using getterspublic 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,Http.MultipartFormData.FilePart<?>> files, 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, Lang lang, boolean directFieldAccess)
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)files
- the current form file dataerrors
- 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.lang
- used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
directFieldAccess
- access fields of form directly during binding instead of using getterspublic java.lang.Class<T> getBackedType()
protected T blankInstance()
protected long maxJsonChars()
protected int maxJsonDepth()
protected java.util.Map<java.lang.String,java.lang.String> requestData(Http.Request request)
protected void fillDataWith(java.util.Map<java.lang.String,java.lang.String> data, java.util.Map<java.lang.String,java.lang.String[]> urlFormEncoded)
protected java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> requestFileData(Http.Request request)
protected <A> java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> resolveDuplicateFilePartKeys(java.util.List<Http.MultipartFormData.FilePart<A>> fileParts)
protected <T> void fillDataWith(java.lang.String key, java.util.Map<java.lang.String,T> data, int valuesCount, java.util.function.Function<java.lang.Integer,T> getValueByIndex)
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> bindFromRequestData(Lang lang, TypedMap attrs, java.util.Map<java.lang.String,java.lang.String[]> requestData, java.lang.String... allowedFields)
lang
- used for validators and formatters during binding and is part of Constraints.ValidationPayload
. Later also used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
.
For these methods the lang can be change via withLang(Lang)
.attrs
- will be passed to validators via Constraints.ValidationPayload
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> bindFromRequestData(Lang lang, TypedMap attrs, java.util.Map<java.lang.String,java.lang.String[]> requestData, java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> requestFileData, java.lang.String... allowedFields)
lang
- used for validators and formatters during binding and is part of Constraints.ValidationPayload
. Later also used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
.
For these methods the lang can be change via withLang(Lang)
.attrs
- will be passed to validators via Constraints.ValidationPayload
requestData
- the map of data to bind fromrequestFileData
- the map of file data to bind fromallowedFields
- the fields that should be bound to the form, all fields if not specified.@Deprecated public Form<T> bind(Lang lang, TypedMap attrs, com.fasterxml.jackson.databind.JsonNode data, java.lang.String... allowedFields)
bind(Lang, TypedMap, JsonNode, long,
String...)
instead to specify the maximum chars that should be consumed by the flattened
form representation of the JSON.lang
- used for validators and formatters during binding and is part of Constraints.ValidationPayload
. Later also used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
.
For these methods the lang can be change via withLang(Lang)
.attrs
- will be passed to validators via Constraints.ValidationPayload
data
- data to submitallowedFields
- the fields that should be bound to the form, all fields if not specified.public Form<T> bind(Lang lang, TypedMap attrs, com.fasterxml.jackson.databind.JsonNode data, long maxChars, java.lang.String... allowedFields)
lang
- used for validators and formatters during binding and is part of Constraints.ValidationPayload
. Later also used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
.
For these methods the lang can be change via withLang(Lang)
.attrs
- will be passed to validators via Constraints.ValidationPayload
data
- data to submitmaxChars
- the maximum number of chars allowed to be used in the intermediate map
representation of the JSON. `parse.DefaultMaxTextLength` is recommended to passed for this
parameter.allowedFields
- the fields that should be bound to the form, all fields if not specified.public Form<T> bind(Lang lang, TypedMap attrs, com.fasterxml.jackson.databind.JsonNode data, long maxChars, int maxDepth, java.lang.String... allowedFields)
lang
- used for validators and formatters during binding and is part of Constraints.ValidationPayload
. Later also used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
.
For these methods the lang can be change via withLang(Lang)
.attrs
- will be passed to validators via Constraints.ValidationPayload
data
- data to submitmaxChars
- the maximum number of chars allowed to be used in the intermediate map
representation of the JSON. `parse.DefaultMaxTextLength` is recommended to passed for this
parameter.maxDepth
- the maximum depth allowed for JSON objects and arrays.allowedFields
- 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(Lang lang, TypedMap attrs, java.util.Map<java.lang.String,java.lang.String> data, java.lang.String... allowedFields)
lang
- used for validators and formatters during binding and is part of Constraints.ValidationPayload
. Later also used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
.
For these methods the lang can be change via withLang(Lang)
.attrs
- will be passed to validators via Constraints.ValidationPayload
data
- data to submitallowedFields
- the fields that should be bound to the form, all fields if not specified.public Form<T> bind(Lang lang, TypedMap attrs, java.util.Map<java.lang.String,java.lang.String> data, java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files, java.lang.String... allowedFields)
lang
- used for validators and formatters during binding and is part of Constraints.ValidationPayload
. Later also used for formatting when retrieving a field (via field(String)
or apply(String)
) and for translations in errorsAsJson()
.
For these methods the lang can be change via withLang(Lang)
.attrs
- will be passed to validators via Constraints.ValidationPayload
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()
files()
to access files.public java.util.Map<java.lang.String,Http.MultipartFormData.FilePart<?>> files()
rawData()
to access other form data.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()
public java.util.Optional<ValidationError> globalError()
public java.util.List<ValidationError> errors()
public java.util.List<ValidationError> errors(java.lang.String key)
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 T get(Lang lang)
value()
instead.lang
- if an IllegalStateException gets thrown it's used to translate the form errors
within that exceptionjava.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 apply(java.lang.String key, Lang lang)
key
- field namelang
- the language to use for the formatterpublic Form.Field field(java.lang.String key)
key
- field namepublic Form.Field field(java.lang.String key, Lang lang)
key
- field namelang
- used for formattingpublic java.util.Optional<Lang> lang()
field(String)
or
apply(String)
) and for translations in errorsAsJson()
. For these methods
the lang can be change via withLang(Lang)
.public Form<T> withLang(Lang lang)
field(String)
or apply(String)
) and for translations in errorsAsJson()
.public Form<T> withDirectFieldAccess(boolean directFieldAccess)
directFieldAccess
- true
enables direct field access during form binding, false
disables it and uses getters instead. If null
falls back to config default.public java.lang.String toString()
toString
in class java.lang.Object