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)
Creates a new
Form . |
Form(java.lang.String name,
java.lang.Class<T> clazz) |
Form(java.lang.String name,
java.lang.Class<T> clazz,
java.lang.Class<?> groups) |
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,
F.Option<T> value) |
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,
F.Option<T> value,
java.lang.Class<?> groups)
Creates a new
Form . |
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.
|
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()
Instantiates a dynamic form.
|
static <T> Form<T> |
form(java.lang.Class<T> clazz)
Instantiates a new form that wraps the specified class.
|
static <T> Form<T> |
form(java.lang.Class<T> clazz,
java.lang.Class<?> group)
Instantiates a new form that wraps the specified class.
|
static <T> Form<T> |
form(java.lang.String name,
java.lang.Class<T> clazz)
Instantiates a new form that wraps the specified class.
|
static <T> Form<T> |
form(java.lang.String name,
java.lang.Class<T> clazz,
java.lang.Class<?> group)
Instantiates a new form that wraps the specified class.
|
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) |
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() |
F.Option<T> |
value()
Retrieves the actual form value.
|
public Form(java.lang.Class<T> clazz)
Form
.clazz
- wrapped classpublic Form(java.lang.String name, java.lang.Class<T> clazz)
public Form(java.lang.String name, java.lang.Class<T> clazz, java.lang.Class<?> groups)
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, F.Option<T> value)
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, F.Option<T> value, java.lang.Class<?> groups)
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 successfulpublic static DynamicForm form()
public static <T> Form<T> form(java.lang.Class<T> clazz)
public static <T> Form<T> form(java.lang.String name, java.lang.Class<T> clazz)
public static <T> Form<T> form(java.lang.String name, java.lang.Class<T> clazz, java.lang.Class<?> group)
public static <T> Form<T> form(java.lang.Class<T> clazz, java.lang.Class<?> group)
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)
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 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()
public 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 errot 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