|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object play.data.Form<T>
public class Form<T>
Helper to manage HTML form description, submission and validation.
Nested Class Summary | |
---|---|
static interface |
Form.Display
Defines a form element's display name. |
static class |
Form.Field
A form field. |
Constructor Summary | |
---|---|
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 . |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
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 successfulMethod Detail |
---|
protected 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 submit
public Form<T> bind(java.util.Map<java.lang.String,java.lang.String> data, java.lang.String... allowedFields)
data
- data to submit
public java.util.Map<java.lang.String,java.lang.String> data()
public java.lang.String name()
public F.Option<T> value()
public Form<T> fill(T value)
value
- existing value of type T
used to fill this form
public 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 name
public Form.Field field(java.lang.String key)
key
- field name
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |