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 name,
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.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)
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,java.util.List<ValidationError>> errors,
java.util.Optional<T> value,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
Form(java.lang.String name,
java.lang.Class<T> clazz,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
Modifier and Type | Method and Description |
---|---|
Form.Field |
apply(java.lang.String key)
Retrieve 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()
Retrieves the actual form data.
|
void |
discardErrors()
Discard errors of this form
|
ValidationError |
error(java.lang.String key)
Retrieve an error by key.
|
java.util.Map<java.lang.String,java.util.List<ValidationError>> |
errors()
Returns all errors.
|
com.fasterxml.jackson.databind.JsonNode |
errorsAsJson()
Returns the form errors serialized as Json.
|
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)
Retrieve a field.
|
Form<T> |
fill(T value)
Populates this form with an existing value, used for edit forms.
|
static DynamicForm |
form()
Deprecated.
inject a
FormFactory instead, since 2.5.0 |
static <T> Form<T> |
form(java.lang.Class<T> clazz)
Deprecated.
inject a
FormFactory instead, since 2.5.0 |
static <T> Form<T> |
form(java.lang.Class<T> clazz,
java.lang.Class<?> group)
Deprecated.
inject a
FormFactory instead, since 2.5.0 |
static <T> Form<T> |
form(java.lang.String name,
java.lang.Class<T> clazz)
Deprecated.
inject a
FormFactory instead, since 2.5.0 |
static <T> Form<T> |
form(java.lang.String name,
java.lang.Class<T> clazz,
java.lang.Class<?> group)
Deprecated.
inject a
FormFactory instead, since 2.5.0 |
T |
get()
Gets the concrete value 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() |
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()
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()
Returns
true if there are any errors related to this form. |
boolean |
hasGlobalErrors()
Returns
true if there any global errors related to this form. |
java.lang.String |
name() |
void |
reject(java.lang.String error)
Add a global error to this form.
|
void |
reject(java.lang.String error,
java.util.List<java.lang.Object> args)
Adds a global error to this form.
|
void |
reject(java.lang.String key,
java.lang.String error)
Adds an error to this form.
|
void |
reject(java.lang.String key,
java.lang.String error,
java.util.List<java.lang.Object> args)
Adds an error to this form.
|
void |
reject(ValidationError error)
Adds an error to this form.
|
protected java.util.Map<java.lang.String,java.lang.String> |
requestData(Http.Request request) |
java.lang.String |
toString() |
java.util.Optional<T> |
value()
Retrieves the actual form value.
|
public Form(java.lang.Class<T> clazz, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
Form
.clazz
- wrapped classpublic Form(java.lang.String name, java.lang.Class<T> clazz, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
public Form(java.lang.String name, 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.Map<java.lang.String,java.util.List<ValidationError>> errors, java.util.Optional<T> value, 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.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)
Form
.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 fields@Deprecated public static DynamicForm form()
FormFactory
instead, since 2.5.0@Deprecated public static <T> Form<T> form(java.lang.Class<T> clazz)
FormFactory
instead, since 2.5.0@Deprecated public static <T> Form<T> form(java.lang.String name, java.lang.Class<T> clazz)
FormFactory
instead, since 2.5.0@Deprecated public static <T> Form<T> form(java.lang.String name, java.lang.Class<T> clazz, java.lang.Class<?> group)
FormFactory
instead, since 2.5.0@Deprecated public static <T> Form<T> form(java.lang.Class<T> clazz, java.lang.Class<?> group)
FormFactory
instead, since 2.5.0public 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)
public Form<T> bindFromRequest(Http.Request request, java.lang.String... allowedFields)
public Form<T> bindFromRequest(java.util.Map<java.lang.String,java.lang.String[]> requestData, java.lang.String... allowedFields)
public Form<T> bind(com.fasterxml.jackson.databind.JsonNode data, java.lang.String... allowedFields)
data
- data to submitprotected 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)
public Form<T> bind(java.util.Map<java.lang.String,java.lang.String> data, java.lang.String... allowedFields)
data
- data to submitpublic java.util.Map<java.lang.String,java.lang.String> 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 ValidationError globalError()
null
.public java.util.Map<java.lang.String,java.util.List<ValidationError>> errors()
public ValidationError error(java.lang.String key)
public com.fasterxml.jackson.databind.JsonNode errorsAsJson()
public com.fasterxml.jackson.databind.JsonNode errorsAsJson(Lang lang)
public T get()
java.lang.IllegalStateException
- if there are errors binding the form, including the errors as JSON in the messagepublic void reject(ValidationError error)
error
- the ValidationError
to add.public void reject(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 void reject(java.lang.String key, java.lang.String error)
key
- the error keyerror
- the error messagepublic void reject(java.lang.String error, java.util.List<java.lang.Object> args)
error
- the error messageargs
- the errot argumentspublic void reject(java.lang.String error)
error
- the error message.public void discardErrors()
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