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 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)
Creates a new
Form . |
Modifier and Type | Method and Description |
---|---|
Form.Field |
apply(java.lang.String key)
Retrieve a field.
|
Form<T> |
bind(org.codehaus.jackson.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(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.
|
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.
|
org.codehaus.jackson.JsonNode |
errorsAsJson()
Returns the form errors serialized as Json.
|
org.codehaus.jackson.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.
|
T |
get()
Gets the concrete value if the submission was a success.
|
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 |
boolean |
hasGlobalErrors()
Returns
true |
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() |
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 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
.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 successfulprotected java.util.Map<java.lang.String,java.lang.String> requestData()
public Form<T> bindFromRequest(java.lang.String... allowedFields)
public Form<T> bind(org.codehaus.jackson.JsonNode data, java.lang.String... allowedFields)
data
- data to submitpublic 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 org.codehaus.jackson.JsonNode errorsAsJson()
public org.codehaus.jackson.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 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