Package play.data
Class DynamicForm
- Object
-
- play.data.Form<DynamicForm.Dynamic>
-
- play.data.DynamicForm
-
public class DynamicForm extends Form<DynamicForm.Dynamic>
A dynamic form. This form is backed by a simpleHashMap<String,String>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DynamicForm.Dynamic
Simple data structure used byDynamicForm
.-
Nested classes/interfaces inherited from class play.data.Form
Form.Display, Form.Field
-
-
Constructor Summary
Constructors Constructor Description DynamicForm(Map<String,String> data, List<ValidationError> errors, Optional<DynamicForm.Dynamic> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
Creates a new dynamic form.DynamicForm(Map<String,String> data, List<ValidationError> errors, Optional<DynamicForm.Dynamic> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config, Lang lang)
Creates a new dynamic form.DynamicForm(Map<String,String> data, Map<String,Http.MultipartFormData.FilePart<?>> files, List<ValidationError> errors, Optional<DynamicForm.Dynamic> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
Creates a new dynamic form.DynamicForm(Map<String,String> data, Map<String,Http.MultipartFormData.FilePart<?>> files, List<ValidationError> errors, Optional<DynamicForm.Dynamic> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config, Lang lang)
Creates a new dynamic form.DynamicForm(MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
Creates a new empty dynamic form.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description DynamicForm
bind(Lang lang, TypedMap attrs, com.fasterxml.jackson.databind.JsonNode data, long maxChars, String... allowedFields)
Binds Json data to this form - that is, handles form submission.DynamicForm
bind(Lang lang, TypedMap attrs, com.fasterxml.jackson.databind.JsonNode data, String... allowedFields)
Deprecated.DynamicForm
bind(Lang lang, TypedMap attrs, Map<String,String> data, String... allowedFields)
Binds data to this form - that is, handles form submission.DynamicForm
bind(Lang lang, TypedMap attrs, Map<String,String> data, Map<String,Http.MultipartFormData.FilePart<?>> files, String... allowedFields)
Binds data to this form - that is, handles form submission.DynamicForm
bindFromRequest(Http.Request request, String... allowedFields)
Binds request data to this form - that is, handles form submission.DynamicForm
bindFromRequestData(Lang lang, TypedMap attrs, Map<String,String[]> requestData, Map<String,Http.MultipartFormData.FilePart<?>> requestFileData, String... allowedFields)
Binds request data to this form - that is, handles form submission.DynamicForm
discardingErrors()
Optional<ValidationError>
error(String key)
Form.Field
field(String key, Lang lang)
Retrieves a field.<A> Http.MultipartFormData.FilePart<A>
file(String key)
Gets the concrete value only if the submission was a success.Map<String,Http.MultipartFormData.FilePart<?>>
files()
DynamicForm
fill(Map<String,Object> value)
Fills the form with existing data.String
get(String key)
Gets the concrete value only if the submission was a success.Map<String,String>
rawData()
Optional<Object>
value(String key)
Gets the concrete valueDynamicForm
withDirectFieldAccess(boolean directFieldAccess)
Sets if during binding fields of the form should be accessed directly or via getters.DynamicForm
withError(String key, String error)
DynamicForm
withError(String key, String error, List<Object> args)
DynamicForm
withError(ValidationError error)
DynamicForm
withGlobalError(String error)
DynamicForm
withGlobalError(String error, List<Object> args)
DynamicForm
withLang(Lang lang)
A copy of this form with the given lang set which is used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
.-
Methods inherited from class play.data.Form
apply, apply, bind, bindFromRequestData, blankInstance, errors, errors, errorsAsJson, errorsAsJson, field, fill, fillDataWith, fillDataWith, get, get, getArgumentsForConstraint, getBackedType, getMessageForConstraintViolation, globalError, globalErrors, hasErrors, hasGlobalErrors, lang, maxJsonChars, maxJsonDepth, name, requestData, requestFileData, resolveDuplicateFilePartKeys, toString, value
-
-
-
-
Constructor Detail
-
DynamicForm
public DynamicForm(MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
Creates a new empty dynamic form.- Parameters:
messagesApi
- the messagesApi component.formatters
- the formatters component.validatorFactory
- the validatorFactory component.config
- the config component.
-
DynamicForm
public DynamicForm(Map<String,String> data, List<ValidationError> errors, Optional<DynamicForm.Dynamic> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
Creates a new dynamic form.- Parameters:
data
- the current form data (used to display the form)errors
- the collection of errors associated with this formvalue
- optional concrete value if the form submission was successfulmessagesApi
- the messagesApi component.formatters
- the formatters component.validatorFactory
- the validatorFactory component.config
- the config component.
-
DynamicForm
public DynamicForm(Map<String,String> data, Map<String,Http.MultipartFormData.FilePart<?>> files, List<ValidationError> errors, Optional<DynamicForm.Dynamic> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config)
Creates a new dynamic form.- Parameters:
data
- the current form data (used to display the form)files
- the current form file dataerrors
- the collection of errors associated with this formvalue
- optional concrete value if the form submission was successfulmessagesApi
- the messagesApi component.formatters
- the formatters component.validatorFactory
- the validatorFactory component.config
- the config component.
-
DynamicForm
public DynamicForm(Map<String,String> data, List<ValidationError> errors, Optional<DynamicForm.Dynamic> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config, Lang lang)
Creates a new dynamic form.- Parameters:
data
- the current form data (used to display the form)errors
- the collection of errors associated with this formvalue
- optional concrete value if the form submission was successfulmessagesApi
- the messagesApi component.formatters
- the formatters component.validatorFactory
- the validatorFactory component.config
- the config component.lang
- used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
-
DynamicForm
public DynamicForm(Map<String,String> data, Map<String,Http.MultipartFormData.FilePart<?>> files, List<ValidationError> errors, Optional<DynamicForm.Dynamic> value, MessagesApi messagesApi, Formatters formatters, javax.validation.ValidatorFactory validatorFactory, com.typesafe.config.Config config, Lang lang)
Creates a new dynamic form.- Parameters:
data
- the current form data (used to display the form)files
- the current form file dataerrors
- the collection of errors associated with this formvalue
- optional concrete value if the form submission was successfulmessagesApi
- the messagesApi component.formatters
- the formatters component.validatorFactory
- the validatorFactory component.config
- the config component.lang
- used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
-
-
Method Detail
-
get
public String get(String key)
Gets the concrete value only if the submission was a success. If the form is invalid because of validation errors or you try to access a file field this method will return null. If you want to retrieve the value even when the form is invalid usevalue(String)
instead. If you want to retrieve a file field usefile(String)
instead.- Parameters:
key
- the string key.- Returns:
- the value, or null if there is no match.
-
file
public <A> Http.MultipartFormData.FilePart<A> file(String key)
Gets the concrete value only if the submission was a success. If the form is invalid because of validation errors or you try to access a non-file field this method will return null. If you want to retrieve the value even when the form is invalid usevalue(String)
instead. If you want to retrieve a non-file field useget(String)
instead.- Parameters:
key
- the string key.- Returns:
- the value, or null if there is no match.
-
value
public Optional<Object> value(String key)
Gets the concrete value- Parameters:
key
- the string key.- Returns:
- the value
-
rawData
public Map<String,String> rawData()
- Overrides:
rawData
in classForm<DynamicForm.Dynamic>
- Returns:
- the actual form data as unmodifiable map. Does not contain file data, use
Form.files()
to access files.
-
files
public Map<String,Http.MultipartFormData.FilePart<?>> files()
- Overrides:
files
in classForm<DynamicForm.Dynamic>
- Returns:
- the the files as unmodifiable map. Use
Form.rawData()
to access other form data.
-
fill
public DynamicForm fill(Map<String,Object> value)
Fills the form with existing data.- Parameters:
value
- the map of values to fill in the form.- Returns:
- the modified form.
-
bindFromRequest
public DynamicForm bindFromRequest(Http.Request request, String... allowedFields)
Description copied from class:Form
Binds request data to this form - that is, handles form submission.- Overrides:
bindFromRequest
in classForm<DynamicForm.Dynamic>
- Parameters:
request
- the request to bind data from.allowedFields
- the fields that should be bound to the form, all fields if not specified.- Returns:
- a copy of this form filled with the new data
-
bindFromRequestData
public DynamicForm bindFromRequestData(Lang lang, TypedMap attrs, Map<String,String[]> requestData, Map<String,Http.MultipartFormData.FilePart<?>> requestFileData, String... allowedFields)
Description copied from class:Form
Binds request data to this form - that is, handles form submission.- Overrides:
bindFromRequestData
in classForm<DynamicForm.Dynamic>
- Parameters:
lang
- used for validators and formatters during binding and is part ofConstraints.ValidationPayload
. Later also used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
. For these methods the lang can be change viaForm.withLang(Lang)
.attrs
- will be passed to validators viaConstraints.ValidationPayload
requestData
- the map of data to bind fromrequestFileData
- the map of file data to bind fromallowedFields
- the fields that should be bound to the form, all fields if not specified.- Returns:
- a copy of this form filled with the new data
-
bind
@Deprecated public DynamicForm bind(Lang lang, TypedMap attrs, com.fasterxml.jackson.databind.JsonNode data, String... allowedFields)
Deprecated.Description copied from class:Form
Binds Json data to this form - that is, handles form submission.- Overrides:
bind
in classForm<DynamicForm.Dynamic>
- Parameters:
lang
- used for validators and formatters during binding and is part ofConstraints.ValidationPayload
. Later also used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
. For these methods the lang can be change viaForm.withLang(Lang)
.attrs
- will be passed to validators viaConstraints.ValidationPayload
data
- data to submitallowedFields
- the fields that should be bound to the form, all fields if not specified.- Returns:
- a copy of this form filled with the new data
-
bind
public DynamicForm bind(Lang lang, TypedMap attrs, com.fasterxml.jackson.databind.JsonNode data, long maxChars, String... allowedFields)
Description copied from class:Form
Binds Json data to this form - that is, handles form submission.- Overrides:
bind
in classForm<DynamicForm.Dynamic>
- Parameters:
lang
- used for validators and formatters during binding and is part ofConstraints.ValidationPayload
. Later also used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
. For these methods the lang can be change viaForm.withLang(Lang)
.attrs
- will be passed to validators viaConstraints.ValidationPayload
data
- data to submitmaxChars
- the maximum number of chars allowed to be used in the intermediate map representation of the JSON. `parse.DefaultMaxTextLength` is recommended to passed for this parameter.allowedFields
- the fields that should be bound to the form, all fields if not specified.- Returns:
- a copy of this form filled with the new data
-
bind
public DynamicForm bind(Lang lang, TypedMap attrs, Map<String,String> data, String... allowedFields)
Description copied from class:Form
Binds data to this form - that is, handles form submission.- Overrides:
bind
in classForm<DynamicForm.Dynamic>
- Parameters:
lang
- used for validators and formatters during binding and is part ofConstraints.ValidationPayload
. Later also used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
. For these methods the lang can be change viaForm.withLang(Lang)
.attrs
- will be passed to validators viaConstraints.ValidationPayload
data
- data to submitallowedFields
- the fields that should be bound to the form, all fields if not specified.- Returns:
- a copy of this form filled with the new data
-
bind
public DynamicForm bind(Lang lang, TypedMap attrs, Map<String,String> data, Map<String,Http.MultipartFormData.FilePart<?>> files, String... allowedFields)
Description copied from class:Form
Binds data to this form - that is, handles form submission.- Overrides:
bind
in classForm<DynamicForm.Dynamic>
- Parameters:
lang
- used for validators and formatters during binding and is part ofConstraints.ValidationPayload
. Later also used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
. For these methods the lang can be change viaForm.withLang(Lang)
.attrs
- will be passed to validators viaConstraints.ValidationPayload
data
- data to submitallowedFields
- the fields that should be bound to the form, all fields if not specified.- Returns:
- a copy of this form filled with the new data
-
field
public Form.Field field(String key, Lang lang)
Description copied from class:Form
Retrieves a field.- Overrides:
field
in classForm<DynamicForm.Dynamic>
- Parameters:
key
- field namelang
- used for formatting- Returns:
- the field (even if the field does not exist you get a field)
-
error
public Optional<ValidationError> error(String key)
- Overrides:
error
in classForm<DynamicForm.Dynamic>
- Parameters:
key
- the field name associated with the error.- Returns:
- an error by key
-
withError
public DynamicForm withError(ValidationError error)
- Overrides:
withError
in classForm<DynamicForm.Dynamic>
- Parameters:
error
- theValidationError
to add to the returned form.- Returns:
- a copy of this form with the given error added.
-
withError
public DynamicForm withError(String key, String error, List<Object> args)
- Overrides:
withError
in classForm<DynamicForm.Dynamic>
- Parameters:
key
- the error keyerror
- the error messageargs
- the error arguments- Returns:
- a copy of this form with the given error added.
-
withError
public DynamicForm withError(String key, String error)
- Overrides:
withError
in classForm<DynamicForm.Dynamic>
- Parameters:
key
- the error keyerror
- the error message- Returns:
- a copy of this form with the given error added.
-
withGlobalError
public DynamicForm withGlobalError(String error, List<Object> args)
- Overrides:
withGlobalError
in classForm<DynamicForm.Dynamic>
- Parameters:
error
- the global error messageargs
- the global error arguments- Returns:
- a copy of this form with the given global error added.
-
withGlobalError
public DynamicForm withGlobalError(String error)
- Overrides:
withGlobalError
in classForm<DynamicForm.Dynamic>
- Parameters:
error
- the global error message- Returns:
- a copy of this form with the given global error added.
-
discardingErrors
public DynamicForm discardingErrors()
- Overrides:
discardingErrors
in classForm<DynamicForm.Dynamic>
- Returns:
- a copy of this form but with the errors discarded.
-
withLang
public DynamicForm withLang(Lang lang)
Description copied from class:Form
A copy of this form with the given lang set which is used for formatting when retrieving a field (viaForm.field(String)
orForm.apply(String)
) and for translations inForm.errorsAsJson()
.- Overrides:
withLang
in classForm<DynamicForm.Dynamic>
-
withDirectFieldAccess
public DynamicForm withDirectFieldAccess(boolean directFieldAccess)
Description copied from class:Form
Sets if during binding fields of the form should be accessed directly or via getters.- Overrides:
withDirectFieldAccess
in classForm<DynamicForm.Dynamic>
- Parameters:
directFieldAccess
-true
enables direct field access during form binding,false
disables it and uses getters instead. Ifnull
falls back to config default.
-
-