users@jersey.java.net

Re: [Jersey] Resource-level filters and parameters

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 11 Dec 2009 14:13:04 +0100

On Dec 11, 2009, at 12:27 PM, Cemo Koc wrote:

>
> Hi all,
>
> I am planning to use with an impl of JSR-303 with my Jersey service.
> Last
> month Jersey started to support formbean perfectly thanks to Paul.
> (you can
> check
> 1.1.5-ea-SNAPSHOT)
>
> Now after injections occured, I would like to obtain injected
> parameters
> with my filter. And a result of this I can easily validate with
> JSR-303.
>

A filter is not currently appropriate because the filter does not have
any information about the parameters that will be passed to the
resource method. One would need to use some AOP/proxy solution to
intercept the method calls to obtain the parameters.


> Shortly,
>
> public class AccountBean {
>
> @FormParam("acc.type")
> @NotNull
> private Integer type;
> }
>

Why not perform the validation from within the bean itself?

    public class AccountBean {

          @FormParam("acc.type")
          @NotNull
          private Integer type;

          @PostConstruct
          void validate() {
            // Use bean validation here ?
          }
   }

Paul.

>
> @POST
> @Path("live")
> @Consumes({MediaType.APPLICATION_FORM_URLENCODED})
> @Produces({MediaType.TEXT_HTML})
> public Template postLive(@Inject AccountBean account) {
>
> //............
> }
>
>
> I just want to validate my injected bean with a resource filter. In
> case a
> validation error, a 4xx error could be returned... How can I do
> that? Paul?
> :)
>
> Thanks
> --
> View this message in context: http://n2.nabble.com/Resource-level-filters-and-parameters-tp4150694p4150694.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>