OmniFaces cdi Param does not work using in constructor injection #295

Closed
temaleva opened this Issue Aug 5, 2016 · 3 comments

Projects

None yet

2 participants

@temaleva
temaleva commented Aug 5, 2016

I have the application that uses together omnifaces, deltaspike and weld as cdi implementation.
trying to use Param in this code to be injected in constructor

public class RequestParameterHelperImpl{

String token;


    @Inject
    RequestParameterHelperImpl( @Param String token) {
        this.token = token;
    }
}`

I get following Deployment Exception. 
Weld is able to find deltaspike property producer, (but that is not match by qualifier and this OK) and is not able to find omnifaces Param.
(With field injection everything works fine.)

org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type String with qualifiers @Param
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject com.xxx.api.util.RequestParameterHelperImpl(@Param String)
  at com.xxx.api.util.RequestParameterHelperImpl.<init>(RequestParameterHelperImpl.java:0)
WELD-001475: The following beans match by type, but none have matching qualifiers:
  - Producer Method [String] with qualifiers [@ConfigProperty @Any] declared as [[BackedAnnotatedMethod] @Produces @Dependent @ConfigProperty public org.apache.deltaspike.core.impl.config.DefaultConfigPropertyProducer.produceStringConfiguration(InjectionPoint)]

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:372)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:293)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:167)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:531)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

@BalusC
Member
BalusC commented Aug 5, 2016

@Param is only supported on fields, not on method arguments.

We will clarify documentation on this.

@BalusC
Member
BalusC commented Aug 14, 2016 edited

I have to take back my previous comment. It actually worked in Tomcat + Weld 2.3.5, but you have to explicitly specify a name.

@Named
@RequestScoped
public class Bean {

    @Inject
    public Bean(@Param(name="token") String token) {
        // ...
    }

}

Only dynamic types (i.e. non-String types) are not supported and will produce exactly the exception as you reported.

Not sure why String didn't work for you, but extracting the name from the constructor argument will not work (this information is not available in bytecode). I will at least improve the documentation on this and add support for dynamic types here.

@BalusC BalusC closed this in 245ae13 Aug 14, 2016
@BalusC
Member
BalusC commented Aug 14, 2016

Fix is available in today's latest 2.5-SNAPSHOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment