1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<chapter id="_FormParam">
<title>@FormParam</title>
<note>
<para>
RESTEasy <link linkend="_NewParam">supports <code>@FormParam</code> annotations with no parameter name.</link>.
</para>
</note>
<para>
When the input request body is of the type "application/x-www-form-urlencoded", a.k.a. an HTML Form, you can inject individual form parameters from the request body into method parameter values.
</para>
<para>
<programlisting>
<form method="POST" action="/resources/service">
First name:
<input type="text" name="firstname">
<br>
Last name:
<input type="text" name="lastname">
</form>
</programlisting>
</para>
<para>
If you post through that form, this is what the service might look like:
</para>
<para>
<programlisting>
@Path("/")
public class NameRegistry {
@Path("/resources/service")
@POST
public void addName(@FormParam("firstname") String first, @FormParam("lastname") String last) {...}
</programlisting>
</para>
<para>
You cannot combine @FormParam with the default "application/x-www-form-urlencoded" that unmarshalls to a MultivaluedMap<String, String>. i.e. This is illegal:
</para>
<para>
<programlisting>
@Path("/")
public class NameRegistry {
@Path("/resources/service")
@POST
@Consumes("application/x-www-form-urlencoded")
public void addName(@FormParam("firstname") String first, MultivaluedMap<String, String> form) {...}
</programlisting>
</para>
<para>
</para>
</chapter>
|