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 classDynamicForm.DynamicSimple 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 DynamicFormbind(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.DynamicFormbind(Lang lang, TypedMap attrs, com.fasterxml.jackson.databind.JsonNode data, String... allowedFields)Deprecated.DynamicFormbind(Lang lang, TypedMap attrs, Map<String,String> data, String... allowedFields)Binds data to this form - that is, handles form submission.DynamicFormbind(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.DynamicFormbindFromRequest(Http.Request request, String... allowedFields)Binds request data to this form - that is, handles form submission.DynamicFormbindFromRequestData(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.DynamicFormdiscardingErrors()Optional<ValidationError>error(String key)Form.Fieldfield(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()DynamicFormfill(Map<String,Object> value)Fills the form with existing data.Stringget(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 valueDynamicFormwithDirectFieldAccess(boolean directFieldAccess)Sets if during binding fields of the form should be accessed directly or via getters.DynamicFormwithError(String key, String error)DynamicFormwithError(String key, String error, List<Object> args)DynamicFormwithError(ValidationError error)DynamicFormwithGlobalError(String error)DynamicFormwithGlobalError(String error, List<Object> args)DynamicFormwithLang(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:
rawDatain 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:
filesin 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:FormBinds request data to this form - that is, handles form submission.- Overrides:
bindFromRequestin 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:FormBinds request data to this form - that is, handles form submission.- Overrides:
bindFromRequestDatain 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.ValidationPayloadrequestData- 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:FormBinds Json data to this form - that is, handles form submission.- Overrides:
bindin 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.ValidationPayloaddata- 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:FormBinds Json data to this form - that is, handles form submission.- Overrides:
bindin 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.ValidationPayloaddata- 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:FormBinds data to this form - that is, handles form submission.- Overrides:
bindin 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.ValidationPayloaddata- 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:FormBinds data to this form - that is, handles form submission.- Overrides:
bindin 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.ValidationPayloaddata- 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:FormRetrieves a field.- Overrides:
fieldin 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:
errorin classForm<DynamicForm.Dynamic>- Parameters:
key- the field name associated with the error.- Returns:
- an error by key
-
withError
public DynamicForm withError(ValidationError error)
- Overrides:
withErrorin classForm<DynamicForm.Dynamic>- Parameters:
error- theValidationErrorto 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:
withErrorin 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:
withErrorin 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:
withGlobalErrorin 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:
withGlobalErrorin 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:
discardingErrorsin classForm<DynamicForm.Dynamic>- Returns:
- a copy of this form but with the errors discarded.
-
withLang
public DynamicForm withLang(Lang lang)
Description copied from class:FormA 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:
withLangin classForm<DynamicForm.Dynamic>
-
withDirectFieldAccess
public DynamicForm withDirectFieldAccess(boolean directFieldAccess)
Description copied from class:FormSets if during binding fields of the form should be accessed directly or via getters.- Overrides:
withDirectFieldAccessin classForm<DynamicForm.Dynamic>- Parameters:
directFieldAccess-trueenables direct field access during form binding,falsedisables it and uses getters instead. Ifnullfalls back to config default.
-
-