Menno
Menno

Reputation: 12621

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?

Upvotes: 2

Views: 657

Answers (1)

Jan Groth
Jan Groth

Reputation: 14636

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.

Upvotes: 1

Related Questions