Hi Stokes,

This is a frequent use case. For this you can use the sublist("bar") method.
The name comes from the JDK's List interface but I agree that it's not
obvious at first sight.

Best regards,
Jerome  

> -----Message d'origine-----
> De : news [mailto:[EMAIL PROTECTED] De la part de Stokes
> Envoyé : mercredi 7 mars 2007 19:22
> À : [email protected]
> Objet : Reliably getting multiple values for a request parameter
> 
> This is quite trivial, but I want to support a URL like this:
>    http://myhost.com/rest/foos?bar=456&bar=789
> (Basically saying give me a list of all Foos that reference Bar[456] 
> or Bar[789].)
> 
> In my Finder class, I use 
> Request.getResourceRef().getQueryAsForm() to get a
> Form object of all the Parameters.  I really expected a 
> method to give me all
> the values for parameter "bar".  I can call 
> Form.getFirstValue("bar") to get the
> first value, but Form.getValues("bar") returns a comma-delimited list.
> Technically my bar values could have anything encoded in 
> them, so this might be
> convenient but not always safe.
> 
> I find myself using this to get a Collection<String> of the values:
> Form f = request.getResourceRef().getQueryAsForm();
> List<String> v = Arrays.asList(f.getValues("bar", "\t", 
> false).split("\\t"));
> 
> Kind of ugly but concise.  This still assumes there won't be 
> any tab characters
> encoded in the url's parameter values, which is a possibility.
> 
> I know a foolproof way would be to iterate through all 
> Parameters and test each
> Parameter name myself, but I'm just pointing out that there 
> should probably be a
> more elegant way built in.
> 
> Trivial, I know.  Or am I missing something?
> Stokes.
> 

Reply via email to