users@jersey.java.net

[Jersey] FormParam problem in InjectableProvider and Spring

From: Cemo Koc <cem.koc.fwd_at_gmail.com>
Date: Thu, 12 Nov 2009 05:53:12 -0800 (PST)

Hi all and Paul :) ,

My aim is wrapping my form parameters such this:

public class Sample {

    @FormParam("param1")
    String s;

    @QueryParam("x")
    String x;
}


I intuitively implemented such a thing with @Component and expected to work
correctly. But my both parameters has not been set.


@Component
public class SpringSample {
    @FormParam("param1")
    String s;

    @QueryParam("x")
    String x;
}

1) My first question, what can I do work it correctly? (I believe that it
is difficult)


---
My second attempt tried to use native Jersey as in some source codes I
found.
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FormContainerParam {
}
 
@Provider
public class FormContainerParamInjector implements
InjectableProvider<FormContainerParam, Type> {
    private final ResourceContext rc;
    public FormContainerParamInjector(@Context ResourceContext rc) {
        this.rc = rc;
    }
    public ComponentScope getScope() {
        return ComponentScope.PerRequest;
    }
    public Injectable getInjectable(ComponentContext ic, FormContainerParam
a, Type type) {
        if (type instanceof Class) {
            final Class c = (Class) type;
            return new Injectable() {
                public Object getValue() {
                    return rc.getResource(c);
                }
            };
        }
        return null;
    }
}
public Response pickAdvertiser( @FormContainerParam Sample s,
                                @FormParam("param1") String userId,
                                @DefaultValue("1") @FormParam("deneme")
Integer count) {
      //........................
       
    }
In this case, 
the instance variable of Sample class  @FormParam("param1")  String s can
not be injected, but other QueryParam successfully injected. And at the same
time, the method parameter param1 can be injected successfully.
2) My second question is that what is the solution for such implementation?
Why my formParam can not be injected into my instance variable.
Thanks
-- 
View this message in context: http://n2.nabble.com/FormParam-problem-in-InjectableProvider-and-Spring-tp3992897p3992897.html
Sent from the Jersey mailing list archive at Nabble.com.