Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc.
*/
package play.data;
import com.fasterxml.jackson.databind.JsonNode;
import com.typesafe.config.Config;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.validation.ValidatorFactory;
import play.data.format.Formatters;
import play.data.validation.ValidationError;
import play.i18n.Lang;
import play.i18n.MessagesApi;
import play.libs.typedmap.TypedMap;
import play.mvc.Http;
/** A dynamic form. This form is backed by a simple HashMap<String,String> */
public class DynamicForm extends Form {
/** Statically compiled Pattern for checking if a key is already surrounded by "data[]". */
private static final Pattern MATCHES_DATA = Pattern.compile("^data\\[.+\\]$");
/**
* Creates a new empty dynamic form.
*
* @param messagesApi the messagesApi component.
* @param formatters the formatters component.
* @param validatorFactory the validatorFactory component.
* @param config the config component.
*/
public DynamicForm(
MessagesApi messagesApi,
Formatters formatters,
ValidatorFactory validatorFactory,
Config config) {
super(DynamicForm.Dynamic.class, messagesApi, formatters, validatorFactory, config);
}
/**
* Creates a new dynamic form.
*
* @param data the current form data (used to display the form)
* @param errors the collection of errors associated with this form
* @param value optional concrete value if the form submission was successful
* @param messagesApi the messagesApi component.
* @param formatters the formatters component.
* @param validatorFactory the validatorFactory component.
* @param config the config component.
*/
public DynamicForm(
Map data,
List errors,
Optional value,
MessagesApi messagesApi,
Formatters formatters,
ValidatorFactory validatorFactory,
Config config) {
this(
data,
Collections.emptyMap(),
errors,
value,
messagesApi,
formatters,
validatorFactory,
config);
}
/**
* Creates a new dynamic form.
*
* @param data the current form data (used to display the form)
* @param files the current form file data
* @param errors the collection of errors associated with this form
* @param value optional concrete value if the form submission was successful
* @param messagesApi the messagesApi component.
* @param formatters the formatters component.
* @param validatorFactory the validatorFactory component.
* @param config the config component.
*/
public DynamicForm(
Map data,
Map> files,
List errors,
Optional value,
MessagesApi messagesApi,
Formatters formatters,
ValidatorFactory validatorFactory,
Config config) {
this(data, files, errors, value, messagesApi, formatters, validatorFactory, config, null);
}
/**
* Creates a new dynamic form.
*
* @param data the current form data (used to display the form)
* @param errors the collection of errors associated with this form
* @param value optional concrete value if the form submission was successful
* @param messagesApi the messagesApi component.
* @param formatters the formatters component.
* @param validatorFactory the validatorFactory component.
* @param config the config component.
* @param lang used for formatting when retrieving a field (via {@link #field(String)} or {@link
* #apply(String)}) and for translations in {@link #errorsAsJson()}
*/
public DynamicForm(
Map data,
List errors,
Optional value,
MessagesApi messagesApi,
Formatters formatters,
ValidatorFactory validatorFactory,
Config config,
Lang lang) {
this(
data,
Collections.emptyMap(),
errors,
value,
messagesApi,
formatters,
validatorFactory,
config,
lang);
}
/**
* Creates a new dynamic form.
*
* @param data the current form data (used to display the form)
* @param files the current form file data
* @param errors the collection of errors associated with this form
* @param value optional concrete value if the form submission was successful
* @param messagesApi the messagesApi component.
* @param formatters the formatters component.
* @param validatorFactory the validatorFactory component.
* @param config the config component.
* @param lang used for formatting when retrieving a field (via {@link #field(String)} or {@link
* #apply(String)}) and for translations in {@link #errorsAsJson()}
*/
public DynamicForm(
Map data,
Map> files,
List errors,
Optional value,
MessagesApi messagesApi,
Formatters formatters,
ValidatorFactory validatorFactory,
Config config,
Lang lang) {
super(
null,
DynamicForm.Dynamic.class,
data,
files,
errors,
value,
null,
messagesApi,
formatters,
validatorFactory,
config,
lang);
}
/**
* 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 use {@link #value(String)} instead. If you
* want to retrieve a file field use {@link #file(String)} instead.
*
* @param key the string key.
* @return the value, or null if there is no match.
*/
public String get(String key) {
try {
return (String) get().getData().get(asNormalKey(key));
} catch (Exception e) {
return null;
}
}
/**
* 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 use {@link #value(String)} instead. If
* you want to retrieve a non-file field use {@link #get(String)} instead.
*
* @param key the string key.
* @return the value, or null if there is no match.
*/
@SuppressWarnings("unchecked") // cross your fingers
public Http.MultipartFormData.FilePart file(String key) {
try {
return (Http.MultipartFormData.FilePart) get().getData().get(asNormalKey(key));
} catch (Exception e) {
return null;
}
}
/**
* Gets the concrete value
*
* @param key the string key.
* @return the value
*/
public Optional