public interface Form extends MultiValueMap<String,String>
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 by MultiValueMap
.
All instances of this type are immutable.
Calling any mutative method of MultiValueMap
will result in an UnsupportedOperationException
.
import ratpack.handling.Handler; import ratpack.handling.Context; import ratpack.form.Form; import ratpack.form.UploadedFile; import java.util.List; public class Example { public static class FormHandler implements Handler { public void handle(Context context) { Form form = context.parse(Form.class); 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 both GET
and PUT
submission with a single handler.
Modifier and Type | Method and 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 a
parseable object to parse a request body into a Form . |
static Parse<Form,FormParseOpts> |
form(boolean includeQueryParams)
Creates a
parseable object to parse a request body into a Form . |
asMultimap, clear, get, getAll, getAll, put, putAll, remove
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
@Nullable UploadedFile file(String name)
name
- The name of the uploaded file in the formnull
if no file was uploaded by that nameList<UploadedFile> files(String name)
name
- The name of the uploaded files in the formMultiValueMap<String,UploadedFile> files()
static Parse<Form,FormParseOpts> form()
parseable object
to parse a request body into a Form
.
Default options will be used (no query parameters included).
static Parse<Form,FormParseOpts> form(boolean includeQueryParams)
parseable object
to parse a request body into a Form
.includeQueryParams
- whether to include the query parameters from the request in the parsed form