Hi,
Here is a way to combine with beans validation for reuse:
public Collection<FpOrganization> readAll(@Context ResourceContext
rc) {
Range r = rc.get(Range.class);
}
public class Range() {
public final int offset;
public final int limit;
public Range(@PathParam("offset") int offset, @PathParam("limit")
int limit) {
// bean validation code here
}
}
I could add support for a @ResourceParam Range r, which hides the use
of ResourceContext, if you would like this please log an issue.
Paul.
On Apr 30, 2009, at 10:07 PM, Tatu Saloranta wrote:
> 2009/4/30 Felipe Gaścho <fgaucho_at_gmail.com>:
>> below you find an example of resource that returns a collection of
>> entities with pagination ...
>>
>> I was thinking in a standard way to move the logging and validation
>> from this code to something external..
>
> I don't know if this would help, but the Bean Validation API (jsr-303,
> an impl at https://www.hibernate.org/412.html) helps in modularizing
> validation part.
>
> You can annotate fields (or accessors for fields) with constraints,
> and get it check for violations, which can be processed generically. I
> use this for validating web service requests; much cleaner than trying
> to use something like XML schema (IMO).
>
> It may not be a big win for just 2 fields (min, max), plus it's more
> useful with static checks. It can probably handle co-constraints too
> (field1 <= field2 etc), but I haven't had (time) to check that part
> yet.
>
> -+ Tatu +-
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>