Hi,
Injection of form parameters using @FormParam is currently only
supported for parameters of resource methods that consume the media
type application/x-www-form-urlencoded.
Form parameters are different from other parameters. The latter are
independent of any request entity (well strictly speaking some request
headers might not be). IMHO it is not advisable to mix the two layers.
I think what you require is support for form parameter beans, there is
an open issue for this:
https://jersey.dev.java.net/issues/show_bug.cgi?id=125
I think we need something like @FormParamBean annotation that can be
utilized on a resource method parameter. We could also support
@ParamBean for simplifying the case of other parameters. Such
instantiated beans would not obey any life-cycle rules.
Having thought about it a bit more it should be fairly easy to
implement this (including support for constructor injection). I will
try tomorrow.
Paul.
On Nov 12, 2009, at 2:53 PM, Cemo Koc wrote:
>
> 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.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>