简体   繁体   中英

Injecting parameters into Beans, CDI bean VS JSF bean

after some experimenting, I have been able to inject my GET-parameters into an @ManagedBean (thus, a JSF) bean using @ManagedProperty and some EL.

Now, except the approach from reading the parameter map from FacesContext.getCurrentInstance().getExternalContext() , I have not been able to inject my GET-parameters into an @Named (thus, a CDI-) bean.

And so, I have been reading about advantages and disadvantages of JSF beans and CDI beans. In short, I am stuck with two questions: 1st. Will I experience any disadvantages in using JSF beans over CDI beans? 2nd. If so, is there a clean way to inject my GET-parameters into a CDI bean?

I hope that I don't start a flamewar here, but it's certainly safe to say that CDI scopes and dependency-injection mechanisms cover far more ground than JSF scopes do. Generally speaking, you are better off with CDI scopes - but one could go into almost arbitrary details here.

Concerning you problem: Seam Solder brings - among many other things - http-parameter-injection. Check this out.

Update: Should you be afraid of integrating Solder into your project (don't be!), take a look at the relevant source-code which does the magic. You can easily copy it into your project - it's just that the developers behind Solder had a few more cornercases in their mind than you would probably come up with on the spot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM