Package ratpack.core.form
Interface Form
-
public interface Form extends MultiValueMap<String,String>
An uploaded form.The form is modelled as a
MultiValueMap
, with extra methods for dealing with file uploads. That is, uploaded files are not visible via the methods provided byMultiValueMap
.All instances of this type are immutable. Calling any mutative method of
MultiValueMap
will result in anUnsupportedOperationException
.Example usage:
import ratpack.core.handling.Handler; import ratpack.core.handling.Context; import ratpack.core.form.Form; import ratpack.core.form.UploadedFile; import java.util.List; public class Example { public static class FormHandler implements Handler { public void handle(Context context) throws Exception { context.parse(Form.class).then(form -> { UploadedFile file = form.file("someFile.txt"); String param = form.get("param"); List<String> multi = form.getAll("multi"); context.render("form uploaded!"); }); } } }
To include the query parameters from the request in the parsed form, use
form(boolean)
. This can be useful if you want to support bothGET
andPUT
submission with a single handler.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description UploadedFile
file(String name)
Return the first uploaded file with the given name.MultiValueMap<String,UploadedFile>
files()
Returns all of the uploaded files.List<UploadedFile>
files(String name)
Return all of the uploaded files with the given name.static Parse<Form,FormParseOpts>
form()
Creates aparseable object
to parse a request body into aForm
.static Parse<Form,FormParseOpts>
form(boolean includeQueryParams)
Creates aparseable object
to parse a request body into aForm
.-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
-
Methods inherited from interface ratpack.func.MultiValueMap
asMultimap, clear, get, getAll, getAll, put, putAll, remove
-
-
-
-
Method Detail
-
file
@Nullable UploadedFile file(String name)
Return the first uploaded file with the given name.- Parameters:
name
- The name of the uploaded file in the form- Returns:
- The uploaded file, or
null
if no file was uploaded by that name
-
files
List<UploadedFile> files(String name)
Return all of the uploaded files with the given name.- Parameters:
name
- The name of the uploaded files in the form- Returns:
- The uploaded files, or an empty list if no files were uploaded by that name
-
files
MultiValueMap<String,UploadedFile> files()
Returns all of the uploaded files.- Returns:
- all of the uploaded files.
-
form
static Parse<Form,FormParseOpts> form()
Creates aparseable object
to parse a request body into aForm
.Default options will be used (no query parameters included).
- Returns:
- a parse object
-
form
static Parse<Form,FormParseOpts> form(boolean includeQueryParams)
Creates aparseable object
to parse a request body into aForm
.- Parameters:
includeQueryParams
- whether to include the query parameters from the request in the parsed form- Returns:
- a parse object
-
-