File: _FormParam.xml

package info (click to toggle)
resteasy 3.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 34,612 kB
  • sloc: java: 265,492; xml: 27,855; javascript: 405; jsp: 166; python: 101; sh: 15; sql: 3; makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download
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 &quot;application/x-www-form-urlencoded&quot;, a.k.a. an HTML Form, you can inject individual form parameters from the request body into method parameter values.
</para>
<para>

<programlisting>
&lt;form method="POST" action="/resources/service"&gt;
First name: 
&lt;input type="text" name="firstname"&gt;
&lt;br&gt;
Last name: 
&lt;input type="text" name="lastname"&gt;
&lt;/form&gt;
</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 &quot;application/x-www-form-urlencoded&quot; that unmarshalls to a MultivaluedMap&lt;String, String&gt;.  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&lt;String, String&gt; form) {...}

</programlisting>
</para>
<para>


</para>
</chapter>