Hi Savvas,

Thank you for your response; I did try it the way you suggested, and you
are right: the params are bound to the ArrayList.
What I found was that application of the @Size annotation as below, imposes
the constraint that the length of the list be no greater than the specified
max.

@Size(max=1000)
@FormParam("a")
private ArrayList<String> stringList = new ArrayList<String>();

While that constraint is useful to me, I also wanted to impose a constraint
that each individual inbound string be checked that its length falls within
a specified range - in my prior example, between 8 and 10 characters.
Research has led me to believe that this is nontrivial, though I did see
someone had developed and shared a library containing @Each annotations ...
and that there (possibly) may be improvements along these lines that would
only work with Java 8.

I was curious why the method-based solution didn't work (my addString
method) because that actually would do the validation I had in mind. That
said, appreciate the time you took to respond.

Best,
Dave


On Sat, Feb 21, 2015 at 2:57 PM, Savvas Andreas Moysidis <
savvas.andreas.moysi...@gmail.com> wrote:

> Hi Dave,
>
> Not really sure why the bean validation stuff doesn't work but in order to
> bind form params you probably need to configure your resource method and
> binding class in a different way. Try the following:
>
> @GET
> public <my object class, not important>
> resourceMethod(@Valid @*BeanParam* MyParams params)
> {
> ...
> }
>
> public class MyParams {
>
>     @FormParam("a")
>     private ArrayList<String> stringList = new ArrayList<>();
>
> ...
> }
>
> This should bind your form params into your MyParams class.
>
> A minor side note: The convention many frameworks use when binding http
> params at method level is the POJO one (i.e. *set*This()/*get*This()
> rather than addThis() etc)
>
> HTF,
> Savvas
>
> On 19 February 2015 at 19:48, Dave J <devdevdata...@gmail.com> wrote:
>
>> Hello,
>>
>> After some nontrivial research I thought I would try this list in the
>> hopes more expert users could help me figure out where I am going wrong.
>> I am using RESTeasy 3.0.9. I am trying to affect validation of a
>> parameter coming in on the URL for a GET request.
>>
>> I use a class to aggregate validation & storage of the set of parameters
>> coming in on the URL.
>>
>> I start with this:
>>
>> @GET
>> public <my object class, not important>
>> resourceMethod(@Valid @Form MyParams params)
>> {
>> ...
>> }
>>
>> The parameter of interest is a String, and can occur more than once.
>> Let's name it "a".
>> I would like to validate each occurrence (I want to check that its length
>> is within a certain range), and if valid, I would like to add the String to
>> a list. Otherwise, stop and report the error.
>>
>> So within the MyParams class....
>>
>> public class MyParams {
>>
>>     private ArrayList<String> stringList = new ArrayList<String>();
>>
>> ...
>>
>>     // Would rather this return void, but validation doesn't like
>> constraints on void methods
>>     @QueryParam('a")
>>     public String addString(@Size(min=8,max=10) String str) {
>>         stringList.add(str);
>>         return null;
>>      }
>> }
>>
>>
>> However in this scenario, the incoming string is neither validated nor
>> added to the list.
>>
>> Is it possible to do this within RESTeasy? I'm happy to provide more info
>> if needed.
>>
>> Thanks.
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
>> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
>> with Interactivity, Sharing, Native Excel Exports, App Integration & more
>> Get technology previously reserved for billion-dollar corporations, FREE
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Resteasy-users mailing list
>> Resteasy-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/resteasy-users
>>
>>
>
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to