public class Form<T> extends 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(Class<T> clazz,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator)
Creates a new
Form. |
Form(String rootName,
Class<T> clazz,
Class<?>[] groups,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
Form(String rootName,
Class<T> clazz,
Class<?> group,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
Form(String rootName,
Class<T> clazz,
Map<String,String> data,
List<ValidationError> errors,
Optional<T> value,
Class<?>[] groups,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator)
Creates a new
Form. |
Form(String rootName,
Class<T> clazz,
Map<String,String> data,
List<ValidationError> errors,
Optional<T> value,
Class<?> group,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
Form(String rootName,
Class<T> clazz,
Map<String,String> data,
List<ValidationError> errors,
Optional<T> value,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
Form(String rootName,
Class<T> clazz,
Map<String,String> data,
Map<String,List<ValidationError>> errors,
Optional<T> value,
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(String rootName,
Class<T> clazz,
Map<String,String> data,
Map<String,List<ValidationError>> errors,
Optional<T> value,
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(String rootName,
Class<T> clazz,
Map<String,String> data,
Map<String,List<ValidationError>> errors,
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(String rootName,
Class<T> clazz,
MessagesApi messagesApi,
Formatters formatters,
javax.validation.Validator validator) |
| Modifier and Type | Method and Description |
|---|---|
List<ValidationError> |
allErrors()
Returns all errors.
|
Form.Field |
apply(String key)
Retrieves a field.
|
Form<T> |
bind(com.fasterxml.jackson.databind.JsonNode data,
String... allowedFields)
Binds Json data to this form - that is, handles form submission.
|
Form<T> |
bind(Map<String,String> data,
String... allowedFields)
Binds data to this form - that is, handles form submission.
|
Form<T> |
bindFromRequest(Http.Request request,
String... allowedFields)
Binds request data to this form - that is, handles form submission.
|
Form<T> |
bindFromRequest(Map<String,String[]> requestData,
String... allowedFields)
Binds request data to this form - that is, handles form submission.
|
Form<T> |
bindFromRequest(String... allowedFields)
Binds request data to this form - that is, handles form submission.
|
protected T |
blankInstance() |
Map<String,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(String key)
Deprecated.
Deprecated as of 2.6.0. Use
getError(String) instead. |
Map<String,List<ValidationError>> |
errors()
Deprecated.
Deprecated as of 2.6.0. Use
allErrors() instead. |
List<ValidationError> |
errors(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(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 Object[] |
getArgumentsForConstraint(String objectName,
String field,
javax.validation.metadata.ConstraintDescriptor<?> descriptor) |
Class<T> |
getBackedType() |
Optional<ValidationError> |
getError(String key) |
Optional<ValidationError> |
getGlobalError()
Retrieves the first global error (an error without any key), if it exists.
|
protected String |
getMessageForConstraintViolation(javax.validation.ConstraintViolation<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. |
List<ValidationError> |
globalErrors()
Retrieve all global errors - errors without a key.
|
boolean |
hasErrors() |
boolean |
hasGlobalErrors() |
String |
name() |
Map<String,String> |
rawData() |
void |
reject(String error)
Deprecated.
Deprecated as of 2.6.0. Use
withGlobalError(String) instead. |
void |
reject(String error,
List<Object> args)
Deprecated.
Deprecated as of 2.6.0. Use
withGlobalError(String, List) instead. |
void |
reject(String key,
String error)
Deprecated.
Deprecated as of 2.6.0. Use
withError(String, String) instead. |
void |
reject(String key,
String error,
List<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 Map<String,String> |
requestData(Http.Request request) |
String |
toString() |
Optional<T> |
value() |
Form<T> |
withError(String key,
String error) |
Form<T> |
withError(String key,
String error,
List<Object> args) |
Form<T> |
withError(ValidationError error) |
Form<T> |
withGlobalError(String error) |
Form<T> |
withGlobalError(String error,
List<Object> args) |
public Form(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(String rootName, Class<T> clazz, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
public Form(String rootName, Class<T> clazz, Class<?> group, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
public Form(String rootName, Class<T> clazz, Class<?>[] groups, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
public Form(String rootName, Class<T> clazz, Map<String,String> data, List<ValidationError> errors, Optional<T> value, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
@Deprecated public Form(String rootName, Class<T> clazz, Map<String,String> data, Map<String,List<ValidationError>> errors, 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(String rootName, Class<T> clazz, Map<String,String> data, List<ValidationError> errors, Optional<T> value, Class<?> group, MessagesApi messagesApi, Formatters formatters, javax.validation.Validator validator)
@Deprecated public Form(String rootName, Class<T> clazz, Map<String,String> data, Map<String,List<ValidationError>> errors, Optional<T> value, 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(String rootName, Class<T> clazz, Map<String,String> data, List<ValidationError> errors, Optional<T> value, 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(String rootName, Class<T> clazz, Map<String,String> data, Map<String,List<ValidationError>> errors, Optional<T> value, 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.protected T blankInstance()
protected Map<String,String> requestData(Http.Request request)
public Form<T> bindFromRequest(String... allowedFields)
allowedFields - the fields that should be bound to the form, all fields if not specified.public Form<T> bindFromRequest(Http.Request request, 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(Map<String,String[]> requestData, 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, String... allowedFields)
data - data to submitallowedFields - the fields that should be bound to the form, all fields if not specified.protected Object[] getArgumentsForConstraint(String objectName, String field, javax.validation.metadata.ConstraintDescriptor<?> descriptor)
protected String getMessageForConstraintViolation(javax.validation.ConstraintViolation<Object> violation)
violation - the constraint violation.public Form<T> bind(Map<String,String> data, String... allowedFields)
data - data to submitallowedFields - the fields that should be bound to the form, all fields if not specified.@Deprecated public Map<String,String> data()
rawData() instead which returns an unmodifiable map.public String name()
public 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 List<ValidationError> globalErrors()
@Deprecated public ValidationError globalError()
getGlobalError() instead.null.public Optional<ValidationError> getGlobalError()
@Deprecated public Map<String,List<ValidationError>> errors()
allErrors() instead.public List<ValidationError> allErrors()
public List<ValidationError> errors(String key)
key - the field name associated with the error.@Deprecated public ValidationError error(String key)
getError(String) instead.key - the field name associated with the error.public Optional<ValidationError> getError(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.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(String key, String error, List<Object> args)
withError(String, String, List) instead.key - the error keyerror - the error messageargs - the error argumentspublic Form<T> withError(String key, String error, List<Object> args)
key - the error keyerror - the error messageargs - the error arguments@Deprecated public void reject(String key, String error)
withError(String, String) instead.key - the error keyerror - the error messagepublic Form<T> withError(String key, String error)
key - the error keyerror - the error message@Deprecated public void reject(String error, List<Object> args)
withGlobalError(String, List) instead.error - the error messageargs - the error argumentspublic Form<T> withGlobalError(String error, List<Object> args)
error - the global error messageargs - the global error arguments@Deprecated public void reject(String error)
withGlobalError(String) instead.error - the error message.public Form<T> withGlobalError(String error)
error - the global error message@Deprecated public void discardErrors()
discardingErrors() instead.public Form<T> discardingErrors()
public Form.Field apply(String key)
key - field namepublic Form.Field field(String key)
key - field name