1

I have some html forms which have select inputs that can have multiple values selected. When I post them to my Restlet service I only the currently selected value. I know that if this were a plain servlet I could use request.getParameterValues(... to get to the array of selected values, but I can't seem to find the equivalent in Restlet. From what I can tell the service maps the request to a JsonRepresentation but I don't see an equivalent method for accessing the parameter values.

Does anyone know a way to do this with Restlet2.x?

sankofamusician
  • 111
  • 1
  • 3

1 Answers1

1

In fact, it depends on the way you post the form from the client. Your question lets me think that you use URL encoded form (Content-Type: application/x-www-form-urlencoded).

In this case, you can extract the submitted data using the class Form of Restlet, as described below:

public class MyServerResource extends ServerResource {
    @Post
    public void handleForm(Form myForm) {
        // Equivalent from request#getParameterValues for Servlet
        String[] values = myForm.getValuesArray("mykey");
        (...)
    }
}

If you want to get a query parameter, simply use the method getQuery to get the associated form object:

public class MyServerResource extends ServerResource {
    @Post
    public void handleForm(Form myForm) {
        // Equivalent from request#getParameterValues for Servlet
        String[] values = getQuery().getValuesArray("mykey");
        (...)
    }
}

Hope it helps you, Thierry

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360