/** * Binds data to this form - that is, handles form submission. * * @param lang used for validators and formatters during binding and is part of {@link ValidationPayload}. * Later also used for formatting when retrieving a field (via {@link #field(String)} or {@link #apply(String)}) * and for translations in {@link #errorsAsJson()}. For these methods the lang can be change via {@link #withLang(Lang)}. * @param attrs will be passed to validators via {@link ValidationPayload} * @param data data to submit * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data */ @SuppressWarnings("unchecked") public Form<T> bind(Lang lang, TypedMap attrs, Map<String,String> data, String... allowedFields) { return bind(lang, attrs, data, Collections.emptyMap(), allowedFields); }
/** * Binds data to this form - that is, handles form submission. * * @param lang used for validators and formatters during binding and is part of {@link ValidationPayload}. * Later also used for formatting when retrieving a field (via {@link #field(String)} or {@link #apply(String)}) * and for translations in {@link #errorsAsJson()}. For these methods the lang can be change via {@link #withLang(Lang)}. * @param attrs will be passed to validators via {@link ValidationPayload} * @param data data to submit * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data */ @SuppressWarnings("unchecked") public Form<T> bind(Lang lang, TypedMap attrs, Map<String,String> data, String... allowedFields) { return bind(lang, attrs, data, Collections.emptyMap(), allowedFields); }
/** * Binds request data to this form - that is, handles form submission. * * @return a copy of this form filled with the new data */ public Form<T> bindFromRequest(Http.Request request, String... allowedFields) { return bind(requestData(request), allowedFields); }
/** * Binds request data to this form - that is, handles form submission. * * @return a copy of this form filled with the new data */ public Form<T> bindFromRequest(Http.Request request, String... allowedFields) { return bind(requestData(request), allowedFields); }
/** * Binds Json data to this form - that is, handles form submission. * * @param data data to submit * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data * * @deprecated Deprecated as of 2.7.0. Use {@link #bind(Lang, TypedMap, JsonNode, String...)} instead. */ @Deprecated public Form<T> bind(JsonNode data, String... allowedFields) { return bind(ctxLang(), ctxRequestAttrs(), data, allowedFields); }
@Override public DynamicForm bind(Lang lang, TypedMap attrs, Map<String,String> data, Map<String, Http.MultipartFormData.FilePart<?>> files, String... allowedFields) { Form<Dynamic> form = super.bind(lang, attrs, data.entrySet().stream().collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), e -> e.getValue())), files.entrySet().stream().collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), e -> e.getValue())), allowedFields); return new DynamicForm(form.rawData(), form.files(), form.errors(), form.value(), messagesApi, formatters, validatorFactory, config, lang); }
/** * Binds data to this form - that is, handles form submission. * * @param data data to submit * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data * * @deprecated Deprecated as of 2.7.0. Use {@link #bind(Lang, TypedMap, Map, String...)} instead. */ @SuppressWarnings("unchecked") @Deprecated public Form<T> bind(Map<String,String> data, String... allowedFields) { return bind(ctxLang(), ctxRequestAttrs(), data, allowedFields); }
/** * Binds Json data to this form - that is, handles form submission. * * @param data data to submit * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data * * @deprecated Deprecated as of 2.7.0. Use {@link #bind(Lang, TypedMap, JsonNode, String...)} instead. */ @Deprecated public Form<T> bind(JsonNode data, String... allowedFields) { return bind(ctxLang(), ctxRequestAttrs(), data, allowedFields); }
/** * Binds request data to this form - that is, handles form submission. * * @return a copy of this form filled with the new data */ public Form<T> bindFromRequest(String... allowedFields) { return bind(requestData(play.mvc.Controller.request()), allowedFields); }
/** * Binds Json data to this form - that is, handles form submission. * * @param data data to submit * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data * * @deprecated Deprecated as of 2.7.0. Use {@link #bind(Lang, TypedMap, JsonNode, String...)} instead. */ @Deprecated public Form<T> bind(JsonNode data, String... allowedFields) { return bind(ctxLang(), ctxRequestAttrs(), data, allowedFields); }
@Override public DynamicForm bind(Lang lang, TypedMap attrs, Map<String,String> data, Map<String, Http.MultipartFormData.FilePart<?>> files, String... allowedFields) { Form<Dynamic> form = super.bind(lang, attrs, data.entrySet().stream().collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), e -> e.getValue())), files.entrySet().stream().collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), e -> e.getValue())), allowedFields); return new DynamicForm(form.rawData(), form.files(), form.errors(), form.value(), messagesApi, formatters, validatorFactory, config, lang); }
@Override public DynamicForm bind(Lang lang, TypedMap attrs, Map<String,String> data, Map<String, Http.MultipartFormData.FilePart<?>> files, String... allowedFields) { Form<Dynamic> form = super.bind(lang, attrs, data.entrySet().stream().collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), e -> e.getValue())), files.entrySet().stream().collect(Collectors.toMap(e -> asDynamicKey(e.getKey()), e -> e.getValue())), allowedFields); return new DynamicForm(form.rawData(), form.files(), form.errors(), form.value(), messagesApi, formatters, validatorFactory, config, lang); }
/** * Binds request data to this form - that is, handles form submission. * * @return a copy of this form filled with the new data */ public Form<T> bindFromRequest(String... allowedFields) { return bind(requestData(play.mvc.Controller.request()), allowedFields); }
default Form<? extends F> createNewFilledForm(final T context) { try { final F formData = getFormDataClass().getConstructor().newInstance(); fillFormData(formData, context); final Map<String, String> classFieldValues = BeanUtils.describe(formData); final Form<? extends F> filledForm = formFactory().form(getFormDataClass()).bind(classFieldValues); filledForm.discardErrors(); return filledForm; } catch (ReflectiveOperationException e) { throw new RuntimeException("Missing empty constructor for class " + getFormDataClass().getCanonicalName(), e); } }
/** * Binds request data to this form - that is, handles form submission. * * @param request the request to bind data from. * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data */ public Form<T> bindFromRequest(Http.Request request, String... allowedFields) { return bind(this.messagesApi.preferred(request).lang(), request.attrs(), requestData(request), requestFileData(request), allowedFields); }
/** * Binds request data to this form - that is, handles form submission. * * @param request the request to bind data from. * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data */ public Form<T> bindFromRequest(Http.Request request, String... allowedFields) { return bind(this.messagesApi.preferred(request).lang(), request.attrs(), requestData(request), requestFileData(request), allowedFields); }
/** * Binds request data to this form - that is, handles form submission. * * @param request the request to bind data from. * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data */ public Form<T> bindFromRequest(Http.Request request, String... allowedFields) { return bind(this.messagesApi.preferred(request).lang(), request.attrs(), requestData(request), requestFileData(request), allowedFields); }
/** * Binds request data to this form - that is, handles form submission. * * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data * * @deprecated Deprecated as of 2.7.0. Use {@link #bindFromRequest(Http.Request, String...)} instead. */ @Deprecated public Form<T> bindFromRequest(String... allowedFields) { return bind(play.mvc.Controller.ctx().messages().lang(), play.mvc.Controller.request().attrs(), requestData(play.mvc.Controller.request()), requestFileData(play.mvc.Controller.request()), allowedFields); }
/** * Binds request data to this form - that is, handles form submission. * * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data * * @deprecated Deprecated as of 2.7.0. Use {@link #bindFromRequest(Http.Request, String...)} instead. */ @Deprecated public Form<T> bindFromRequest(String... allowedFields) { return bind(play.mvc.Controller.ctx().messages().lang(), play.mvc.Controller.request().attrs(), requestData(play.mvc.Controller.request()), requestFileData(play.mvc.Controller.request()), allowedFields); }
/** * Binds request data to this form - that is, handles form submission. * * @param allowedFields the fields that should be bound to the form, all fields if not specified. * @return a copy of this form filled with the new data * * @deprecated Deprecated as of 2.7.0. Use {@link #bindFromRequest(Http.Request, String...)} instead. */ @Deprecated public Form<T> bindFromRequest(String... allowedFields) { return bind(play.mvc.Controller.ctx().messages().lang(), play.mvc.Controller.request().attrs(), requestData(play.mvc.Controller.request()), requestFileData(play.mvc.Controller.request()), allowedFields); }